Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Jul 2006
    Location
    Cincinnati, OH
    Posts
    85
    Thanks
    1
    Thanked 0 Times in 0 Posts

    getElementById().value issue? works in FF, not in IE

    The following is a piece of AJAX script that I am working on:

    Code:
    $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?

  • #2
    New Coder
    Join Date
    Jul 2006
    Location
    Cincinnati, OH
    Posts
    85
    Thanks
    1
    Thanked 0 Times in 0 Posts
    I figured this out.

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

  • #3
    Regular Coder
    Join Date
    Sep 2005
    Posts
    535
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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...
    If you want answers, write a smart question.

    Yes, someone probably does know how...

    Oh, and if you want to learn, STFW!

  • #4
    New to the CF scene
    Join Date
    Mar 2007
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Smile

    I think you should named is shorter.
    I tried with IE7. OK


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •