Jump to content

PHP/AJAX <Select> innerhtml in IE


PHPorbust

Recommended Posts

Hi,

It appears I ran into the dreaded IE <select> issue with innerhtml.  I have looked at multiple solutions but alas I reach out for help!

The code works beautifully in Safari and Firefox but fails in IE  by simply loading blanks when AJAX is called.

I read up on microsoft.com a DIV may work outside the <select>.  But I must be messing something up.

Thanks for your puzzle solving help!

 

Code:

 

AJAX:

xmlHttp.onreadystatechange=function(){

if(xmlHttp.readyState==4) {

var temp=(xmlHttp.responseText);

document.getElementById("option").innerHTML=temp;

      }

}

var queryString = "?page=" + page;                              

xmlHttp.open("GET","AJAX_page.php" + queryString,true);

xmlHttp.send(null);

 

PHP:

<?php

echo "<form action='next.php' method='POST'>";

echo "<select name='id' id='option'><option value=0>Option_0/option>";

{

echo "<option value ='$id'>$choice</option>";

}

echo "</select>";

echo "<input type='submit' value='Submit'></form>";

?>

 

 

Link to comment
Share on other sites

Since I don't have the full code, I can't try it out.

 

Have you tried this?

 


var xmlhttp;

if (window.XMLHttpRequest)
  { // code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }

 

And... Why are you using a POST form if you're fetching a GET data in AJAX code?

Link to comment
Share on other sites

Hi there Ivan,

 

The rest of the AJAX part is the standard, similar to what you posted, indeed.

The POST is the "Select" choice being sent to a processing page unrelated to the AJAX call. 

Everything is good in Firefox, Safari.  I have it down to the issue being an IE bug that exists with innerhtml used in <Select>.

It is documented by Microsoft in fact.  But their solution eludes me :(

 

 

 

Link to comment
Share on other sites

Replace the entire select box, not just the options list.  Or else replace the options using proper dom methods rather than innerHTML.

 

 

(and use code tags)

<?php
echo "<form action='next.php' method='POST'>";
echo "<div id=\"option\">";
echo "<select name='id'><option value=0>Option_0/option>";
//assuming there is a loop here
echo "<option value ='$id'>$choice</option>";
//end loop
echo "</select>";
echo "</div>";
echo "<input type='submit' value='Submit'></form>";                  
?>

 

Then in your ajax file, just add the select tag to the output.

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.