View Full Version : getElementById().value issue? works in FF, not in IE

02-28-2007, 06:09 PM
The following is a piece of AJAX script that I am working on:

$modifyScript = "function modifyBundle(){//alert('modifyBundle!');\n";
$modifyScript .= "var xmlhttp=false;\n";
$modifyScript .= "try{// Firefox, Opera 8.0+, Safari\n";
$modifyScript .= "xmlHttp=new XMLHttpRequest();\n";
$modifyScript .= "}\n";
$modifyScript .= "catch (e){// Internet Explorer\n";
$modifyScript .= "try{\n";
$modifyScript .= "xmlHttp=new ActiveXObject(\"Msxml2.XMLHTTP\");\n";
$modifyScript .= "}\n";
$modifyScript .= "catch (e){\n";
$modifyScript .= "try{\n";
$modifyScript .= "xmlHttp=new ActiveXObject(\"Microsoft.XMLHTTP\");\n";
$modifyScript .= "}\n";
$modifyScript .= "catch (e){\n";
$modifyScript .= "alert('Your browser does not support AJAX!');\n";
$modifyScript .= "return false;\n";
$modifyScript .= "}\n";
$modifyScript .= "}\n";
$modifyScript .= "}\n";
$modifyScript .= "var arr = new Array();";
$modifyScript .= "for(var i=0;i<document.getElementById('selectedCourses').length;i++){\n";
$modifyScript .= "arr[i] = document.getElementById('selectedCourses')[i].value.replace(/,/g,\"%*%\");";
$modifyScript .= "}alert(arr);\n";
$modifyScript .= "var title = document.getElementById('bundleTitle').value.replace(/&/g,\"\*#*\");";
$modifyScript .= "var sku = document.getElementById('bundleSku').value.replace(/&/g,\"\*#*\");";
$modifyScript .= "var status = '';if(document.getElementById('A').checked){status = 'A'}else{status = 'I'};";
$modifyScript .= "var params = 'bundleTitle='+title+'&bundleSku='+sku+'&bundleStatus='+status+'&courseArray='+arr;\n";
$modifyScript .= "alert(params);xmlHttp.open('POST','bundleAjax.php',true);\n";
$modifyScript .= "xmlHttp.setRequestHeader(\"Content-type\", \"application/x-www-form-urlencoded\");";
$modifyScript .= "xmlHttp.setRequestHeader(\"Content-length\", params.length);";
$modifyScript .= "xmlHttp.setRequestHeader(\"Connection\", \"close\");";
$modifyScript .= "xmlHttp.onreadystatechange=function(){\n";
$modifyScript .= "if(xmlHttp.readyState==4){\nalert('The bundle has been saved!');}\n";
$modifyScript .= "}\n";
$modifyScript .= "xmlHttp.send(params);\n";
$modifyScript .= "return;\n";
$modifyScript .= "}\n";

When I run in FF everything is fine. When I run in IE all of the values I should be getting from the bolded line are empty. I tried getElementById('selectedCourses').options[i].value as well and it didn't work in IE either.

Any ideas what the problem is?

02-28-2007, 08:06 PM
I figured this out.

I needed to be using options[i].text.

03-01-2007, 12:23 AM
Yuck! Another bug in FF that IE has correct (go figure!) I'm assuming that your problem is also that you do not actually have any 'value' attributes in your <option>s. FF will use the text instead, whereas IE (correctly, I think) won't return anything because there is no actual value assigned to it.

Check out this site (http://jszen.blogspot.com/2007/01/ie6-select-value-gotcha.html)...

03-01-2007, 04:22 PM
I think you should named is shorter.
I tried with IE7. OK