Jump to content

[solved]select Field Not Working In Ie - Ajax


Fredrics
 Share

Recommended Posts

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";?>

Edited by Fredrics
Link to comment
Share on other sites

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

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...