Archive

Archive for the ‘JavaScript’ Category

Dynamic SELECT Dropdown via JavaScript

May 20th, 2009

ie_fail

I would just like to preface this article by saying IE sucks. Seriously… standards have been made, all browsers comply EXCEPT Microsoft Internet Explorer. Microsoft = marketing not quality.

I have just recently tried to dynamically generate an option element list for a select element via an AJAX call. This works great in FF and Chrome, but IE7 is just a giant fail. After some research and viewing several solutions, here is mine… straight forward and simple.

HTML:

<span id=”elementid”></span>

JavaScript:

document.getElementById(“elementid”).innerHTML=xmlhttp.responseText;

Server Side Script (PHP):

$result = mysql_query($sql,$dblink);
echo “<select name=’item’>”;
while($row = mysql_fetch_assoc($result)) {
     echo “<option value=’{$row['ID']}’>{$row['ItemName']}</option>”;
}
echo “</select>”;

 

I ended up generating the select elements and the option elements within the JavaScript because IE would not allow me to use innerHTML to place option elements within the select element.

IE = fail

JavaScript, Web Design

website uptime