PDA

View Full Version : Resolved jquery return ok in Firefox, not so in IE


1andyw
04-11-2009, 04:44 PM
Hi,
$(document).ready(function(){
$.post("volgetname.php", function(data){
$('select#vol').html(data);
alert("Select value is: " + data);
//alert returns correct data in firefox and ie
});
$("#vol").change(function(){
displayrecord();
});
function displayrecord(){
//next line should get value of selected option
var volnum=$('select#vol'). val()
alert("value at line 79: " + volnum);
//This alert in firefox returns the value of the select option. In ie, it returns undetermined.
etc.
etc.

I am trying to identify an issue between firefox and IE.
The entire program runs well in firefox.
I have located the area at which ie quits cooperating.
The method of getting the selected option value of a select box on a form is causing a conflict in ie.

This is the form: <form name="volselect" id="volselect" method="post" action="volgetname.php">
<select name="vol" id="vol" size="1" style="width:20em">
<option>FullName</option>
</select>
</form>

Shoud I change the syntax for the select.val for IE?

Thanks,

Andy

Iszak
04-11-2009, 05:01 PM
I have no idea, I tested this and it seemed to work, but maybe try this code I did.

$(document).ready(function(){
jQuery.post('volgetname.php', function(response){
$('#vol').html(data);

alert("Select value is: " + data);
});

$('#vol').change(function(){
var volnum = $(this).val();
alert("Value at line 79: " + volnum);
});
});

1andyw
04-11-2009, 05:38 PM
Substituted your code for mine the result is the same except it now throws errors in ff also:
Notice: Undefined offset: 2 in /home/unix/web/htdocs/m/h/mhanp.org/www/aandymdb/volgethours.php on line 10
mysql_error()

Which leads back to the problem of the select option value not being recognized.

Iszak
04-12-2009, 07:23 AM
I don't see how the replaced code could have caused that error - because that's a PHP error, and looking at your request, it's not like you're sending any data to the page which I've forgotten, that error is completely unrelated to the JavaScript. How about instead of using .val() use .html() when getting the value of the option so var volnum = $(this).html();

If you're trying to do an AJAX request with the select data, you need to pass it otherwise it won't work - because I presume volgetname.php has some dependency on the POST content?

1andyw
04-13-2009, 08:57 AM
Iszak,

You are correct. The php was in error and messed up the script.

Changed: <option> . $var . </option>

to:

<option . $var .> . $var . </option>

Thank you.