PDA

View Full Version : IE 7 Select Box Issue



stewartf
05-24-2009, 02:44 PM
I am new to using Ajax. I am new to PHP. I know enough to be dangerous. That said.
I recently created a page which uses Ajax to gather data for a Select box. The select box is populated in .php and then sent back.
I then created an onClick Function(JavaScript) for that select box to send the value of it to another .php page to gather more information about the selected item. Mozilla is fine. IE 7, no value is sent to the onClick function and thus no value is returned. I have searched 7 hours and have gotten close, but alas found nothing.

Any Ideas.

shadmego
05-24-2009, 03:43 PM
The only thing I can think of is to make sure your IE7 browser is set to allow javascript.

If it is, then there will be more info needed, like code snippets of the suspected program parts that are causing the errors ...

~regards

stewartf
05-24-2009, 03:52 PM
Javascript is enabled.

echo "<select id=\"list\" name=\"name\" size=\"".$numofrows."\" class=\"nut_table\">";
if($numofrows > 0){
while ($rows = mysql_fetch_array($search_query)){
echo "<option id=\"".$rows['pri_key']."\" onclick=\"addToEdit(".$rows['pri_key'].");\">".$rows['name']."</option>";
}

here is the piece of my .php file where the select box is generated. the values for pri_key and name are being pulled from my database via sql.

then there is this...

xmlhttp.onreadystatechange=function(){
if (xmlhttp.readyState==4)
{
document.getElementById("result_box").innerHTML=xmlhttp.responseText;
}

which is the javascript portion which puts the select box on the screen.

the box dislpays fine, and again it works as intended in Mozilla.

stamat
05-24-2009, 04:11 PM
You have missed value='' parameter of <option> tag.

The line in while loop should look like this:
echo "<option value=\"".$rows['pri_key']."\" id=\"".$rows['pri_key']."\" onclick=\"addToEdit(".$rows['pri_key'].");\">".$rows['name']."</option>";

I am not sure this will solve javascript problem, but it should.
Also, I sometimes had problems sending values to javasript functions if they are not in quotes.
Example: addToEdit('".$rows['pri_key']."');. See single quotes sorrounding PHP variable.

Regards

stewartf
05-24-2009, 04:31 PM
Thank you for the heads up on the value attribute. I hadn't thought of that.
This did not fix the problem, though. It is almost as if IE does not see the select box at all. I put a hello alert box at the top of the addToEdit() function, and IE does not even get that far. It was earlier. My option now looks like this...

echo "<option id=\"".$rows['pri_key']."\" value=\"".$rows['pri_key']."\" ondblclick=\"addToEdit(this.value);\">".$rows['name']."</option>";

stamat
05-24-2009, 04:57 PM
I am using Linux, so I do not have Internet Explorer an can not test this.

In www.w3csools.com they say that <option> tag does not support onclick event (on all browsers), but <select> does. You can try adding event to <select> itself.

Example without PHP (just to be more readable):
<select onclick='addToEdit()' id='list'>
options remain the same.

in addToEdit() function:

var x=document.getElementById("list");
var selected = x.options[x.selectedIndex].value
alert(selected);

On this location
http://www.w3schools.com/js/tryit.asp?filename=try_dom_option_index
you can edit example code online and try it instantly from your IE. When you make it to run as you like without PHP, then modify it to work with your database values.

Regards

stewartf
05-24-2009, 05:03 PM
Thanks for that. I was beginning to think I was crazy.
I had the onclick function on the select line at first, but not the value on the option line.
I tried putting the onclick function on each line thinking that would help...
I guess IE requires the value per option and Mozilla doesn't.

Thank you so much...now I can go home.

stamat
05-24-2009, 05:08 PM
Glad to help.

Regards