Fredrics Posted May 26, 2009 Share Posted May 26, 2009 Currently i have a form submitting via ajax to a php page, I have succesfully made this work on firefox and google chrome but i am unable to make this work on IE.I know that IE uses Activexobject to do this process instead and this works fine, however the problem is that this is not working for a select field.Whats wrong?HTML code: <html><body><script language="javascript" type="text/javascript">function ajaxFunction(){ var ajaxRequest; try{ ajaxRequest = new XMLHttpRequest(); } catch (e){ try{ ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try{ ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e){ alert("Your browser broke!"); return false; } } } ajaxRequest.onreadystatechange = function(){ if(ajaxRequest.readyState == 4){ var ajaxDisplay = document.getElementById('ajaxDiv'); ajaxDisplay.innerHTML = ajaxRequest.responseText; } } var site = document.getElementById('site').value; var Name = document.getElementById('Name').value; var queryString = "?site=" + site + "&Name=" + Name; ajaxRequest.open("GET", "test.php" + queryString, true); ajaxRequest.send(null); }</script><title>Project Catastrophe Vote For Rewards</title><form action="frame.php" method="post">Name:<input type='text' id='Name' maxlength="12"/> </br>Site:<select id="site"> <option>xtreme</option> <option>mmorpg</option> <option>gtop</option> <option>gamesites200</option> <option>topofgames</option> <option>topmmo</option> <option>gamesites100</option></select></br><input type='button' onclick='ajaxFunction()' value='Submit' /></form><div id='ajaxDiv'>Your result will display here</div></body></html> PHP code: <?php$site = $_GET['site'];$name = $_GET['Name'];echo "$site";echo "$name";?> Link to comment Share on other sites More sharing options...
jesh Posted May 26, 2009 Share Posted May 26, 2009 Rather than: var site = document.getElementById('site').value; You might try the following: var select = document.getElementById('site');var site = select.options[select.selectedIndex].value; Link to comment Share on other sites More sharing options...
Fredrics Posted May 26, 2009 Author Share Posted May 26, 2009 Unfortunately that has not worked, Here is the live demohttp://catastrophe.no-ip.info/copy1/votenow.html Link to comment Share on other sites More sharing options...
Ingolme Posted May 26, 2009 Share Posted May 26, 2009 It works correctly for me in Firefox 3. It doesn't in Internet Explorer. But I recommend always setting the value attribute on your <option> tags: <option value="xtreme">xtreme</option><option value="mmorpg">mmorpg</option><option value="gtop">gtop</option><option value="gamesites200">gamesites200</option><option value="topofgames">topofgames</option><option value="topmmo">topmmo</option><option value="gamesites100">gamesites100</option> The text between the <option> tags is what is displayed in the box, but the value that is read is what's in the value attribute. Link to comment Share on other sites More sharing options...
Fredrics Posted May 26, 2009 Author Share Posted May 26, 2009 Great job, it worked. I have never seen that done before - But as they say you learn something new everyday.Thank you very much. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.