I have this; <select id='list'> <option value='1'>First</option> <option value='2'>Second </option> <option value='3'>Third </option> </select> i want to specifically get the option selected and put it an a variable, then alert...
]]>I have this;
<select id='list'>
<option value='1'>First</option>
<option value='2'>Second </option>
<option value='3'>Third </option>
</select>
i want to specifically get the option selected and put it an a variable, then alert what’s in the variable.
I tried
var value = $ ("#list option:selected").text();
alert(value);
but its not working
Ps: i need the selected value in a variable.
Thanks
I have written the following code using jquery and php to submit the form when user clicks on save button, the form is getting submitted successfully but the forma data...
]]>I have written the following code using jquery and php to submit the form when user clicks on save button, the form is getting submitted successfully but the forma data is empty (post data)
This is what i am doing :
I am checking whether the save button is clicked, if so then i am sending a mail and setting the form action then submitting the form.
<form id= "contactform" method='POST'>
.......
<input type='submit' name='submit_details' value=Save />
</form>
<script type="text/javascript">
function submit_form()
{
$ ("#contactform").attr("action","https://functions.php");
$ ("#contactform").submit()
}
<?php
if(isset($ _POST['submit_details']))
{
mail("[email protected]", $ subject, $ mailbody, $ headers);
echo "<script> submit_form(); </script>";
}
?>
but when i call the the javascript function directly, the form data will pass
<form id= "contactform" onsubmit='javascript:submit_form();' method='POST'>
So, what is the problem here.
]]>I not know why in following js code alert is empty without html code, my view have html code, and my_class work true for other controller, when i get alert...
]]>I not know why in following js code alert is empty without html code, my view have html code, and my_class work true for other controller, when i get alert this means it is work true js code but get data of php code without html. what do i do?
function guide_show($ offset = 0) {
$ find = $ this -> input -> post('find');
$ where = "name LIKE '%$ find%' OR phone LIKE '%$ find%' OR mobile LIKE '%$ find%' OR address LIKE '%$ find%' OR date_submit LIKE '%$ find%' OR useradmin_submit LIKE '%$ find%'";
$ table = "guide";
$ url_pag = "admin/submits/guide_show";
$ order = "id";
$ data = $ this -> my_class -> show($ where, $ table, $ url_pag, $ order, $ offset);
$ this->load->view('admin/guide_show', $ data);
}
jQuery:
$ .ajax({
type: "POST",
dataType: "html",
url: url,
data: dataString,
cache: false,
success: function (html) {
alert(html)
},
"error": function (x, y, z) {
// callback to run if an error occurs
alert("An error has occured:\n" + x + "\n" + y + "\n" + z);
}
})
Here is My_class(library): http://pastebin.com/6DxjmBFC
Here is my htm code in view(guide_show): http://pastebin.com/mtubjzvB
]]>I want get last class in .fine_class, but my code give me undefined. how can fix it? Example: http://jsfiddle.net/gBxan/ <div class="find_class"> <div class="class1"></div> <div class="class2"></div> <div class="class3"></div> <!-- I wan...
]]>I want get last class in .fine_class
, but my code give me undefined
. how can fix it?
Example: http://jsfiddle.net/gBxan/
<div class="find_class">
<div class="class1"></div>
<div class="class2"></div>
<div class="class3"></div> <!-- I wan get class this div -->
</div>
var find = $ ('div.find_class div:last').find('div:last').attr('class');
alert(find);
]]>I am looking to make a nice transition effect for a dynamic user layout system I have created. My layout relies on a session being either the value of 1...
]]>I am looking to make a nice transition effect for a dynamic user layout system I have created.
My layout relies on a session being either the value of 1 or 2, I then call the layout using a switch statement.
switch ($ _SESSION['layout']) {
case 1: break;
case 2: break;
}
I have also created a button that they can click to change the layout using ajax. The jquery for this is like so:
$ ('#changeLayout').click(function() {
$ .ajax({data: {changeLayout: 'mainLayout'}});
$ ('#fluidWrap').fadeOut();
setTimeout(function() {
window.location = 'http://www.example.com/preferences';
}, 1000);
return false;
});
The ajax is as follows:
if ($ _SESSION['layout'] == 1) {
$ q = $ dbc -> prepare("UPDATE layout SET layout = 2 WHERE id = ?");
$ q -> execute(array($ _SESSION['id']));
$ _SESSION['layout'] = '2';
}
else {
$ q = $ dbc -> prepare("UPDATE layout SET layout = 1 WHERE id = ?");
$ q -> execute(array($ _SESSION['id']));
$ _SESSION['layout'] = '1';
}
Now at the minute when the user clicks the button to change the layout the div #fluidWrap fades out, the ajax request has 1 second to change the session data and add it to the database, and the page reloads. All works well.
I was wondering how I can improve on this to maybe make a transition effect where the page slides out and slides back in again, how would I go about doing this?
I can’t add an effect with jquery for the div #fluidWrap to fade in, as on every load of the page it will of course fade in. How can I tell jquery to only fade in the body if the button was clicked after a page load?
]]>I am new to jQuery. I have to query 2 web services and based on an attribute value in first web service I have to query the next one and...
]]>I am new to jQuery. I have to query 2 web services and based on an attribute value in first web service I have to query the next one and populate the result in a table using data from both web services.
Please have a look at the code at http://jsfiddle.net/ykPXZ/2/ . I am trying to append the table data to a div having id=”tableData”. I am getting the data from the web service and I have checked the console logs to see whether the data is getting appended to the variable tableDataA and it is getting appended but I am not to display the data on the web page. Somehow it is getting rewritten or deleted.
Please tell me if this is the best approach for solving this problem. Please suggest a better approach to it.
Thanks.
]]>I am trying to post form values via AJAX to a php file. How do I collect my form values to send inside of the “data” parameter? $ .ajax({ type:...
]]>I am trying to post form values via AJAX to a php file. How do I collect my form values to send inside of the “data” parameter?
$ .ajax({
type: "POST",
data: "submit=1&username="+username+"&email="+email+"&password="+password+"&passconf="+passconf,
url: "http://rt.ja.com/includes/register.php",
success: function(data)
{
//alert(data);
$ ('#userError').html(data);
$ ("#userError").html(userChar);
$ ("#userError").html(userTaken);
}
});
HTML:
<div id="border">
<form action="/" id="registerSubmit">
<div id="userError"></div>
Username: <input type="text" name="username" id="username" size="10"/><br>
<div id="emailError" ></div>
Email: <input type="text" name="email" size="10" id="email"/><br>
<div id="passError" ></div>
Password: <input type="password" name="password" size="10" id="password"/><br>
<div id="passConfError" ></div>
Confirm Password: <input type="password" name="passconf" size="10" id="passconf"/><br>
<input type="submit" name="submit" value="Register" />
</form>
</div>
]]>I wrote a small validation script (partially as an exercise in learning) but I can’t figure out how to make it detect default values in the input fields. It seems...
]]>I wrote a small validation script (partially as an exercise in learning) but I can’t figure out how to make it detect default values in the input fields. It seems like I need to store the default value in a variable and then add another OR in there to check if the current value matches that default value but I can’t quite figure out how to do that. I can’t put the variable inside the function executed on the click because then it takes the value at that point and uses that. Any help would be appreciated. I thought about just using “placeholder” but I wanted to make it work in IE. thanks in advance.
$ ('.submit').click(function() {
var ret_val = true;
var emailaddressVal = $ ("#email").val();
var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$ /;
$ ('.required').each(function(){
if($ (this).val().length === 0 || $ (this).find("option:selected").val() == "none")
{
$ ('#errormessage').removeClass('requiredmessage');
ret_val = false;
$ (this).addClass('warning');
}
else if($ (this).val().length != 0)
{
$ (this).removeClass('warning');
}
});
if(!emailReg.test(emailaddressVal))
{
$ ('#emailerrormessage').removeClass('requiredmessage');
$ ('#email').addClass('warning');
ret_val = false;
}
else
{
$ ('#emailerrormessage').addClass('requiredmessage');
}
return ret_val;
});
]]>I have a series of checkboxes that represent various food items. I would like to create a subtotal depending on what the user selects. I have been looking through the...
]]>I have a series of checkboxes that represent various food items. I would like to create a subtotal depending on what the user selects. I have been looking through the jQuery documentation and I see how to update the the value of a textbox however how does one do a new tally every time a new checkbox is “checked”. Also, what happens when a checkbox is “un-selected”. Is there a way to store the value of each item in the HTML code of the checkbox?
I have a jsFiddle example I have been fooling with here …
]]>Question by Kazuma: getting xml without server side script? Is it possible to retrieve an xml file on a different server from with in the HTML using something like Javascript...
]]>Question by Kazuma: getting xml without server side script?
Is it possible to retrieve an xml file on a different server from with in the HTML using something like Javascript or Ajax? I tried using jQuery after I figured out ajax wouldn’t let me retrieve data that didn’t have the same host name but I recieve the same result.
Need some way to load the XML into html… I was thinking XLST but I can’t use it because I’m not the one creating the website. I’m only providing the backend. This XML should be included just by a simple Javascript function which converts and prints the XML into the HTML.
Best answer:
Answer by Alarice Chan
I’m not quite sure what script you can use to get content if JavaScript doesn’t work but it could be your server’s fault or the other server’s that the script couldn’t access the XML. XML should be accessible to the browser as long as your server allows others to integrate it to other websites and the other server also permits foreign server content (could be a security feature to prevent content stealing or cross-server scripting vulnerability).
What do you think? Answer below!
]]>