Jump to content

Recommended Posts

Hi,

 

I've created a couple of dropdown boxes. The user selects their option from the first box and this activates an ajax call to populate the second box.

 

If the form doesn't validate and the page and form is reloaded, it remembers my selections.

 

However, it doesn't recognise that I have made a selection and the post data for that drop down is empty, which leads me to be believe that the page is not posting the data from the ajax generated drop down list.

 

I've checked my code and this is sound.

 

Any help is much appreciated.

 

Here's the html:

 

<select name="hotel_name_1" onchange="getLocations('1', this.value)">
<option>Select Hotel</option>
<!--LIST OF OPTIONS-->
</select>

<span id="locations1">
<select name="hotel_selection_1">
<option></option>
</select>
</span>

 

And here's the javascript:

 

<script type="text/javascript">
function getXMLHTTP() { //fuction to return the xml http object
	var xmlhttp=false;	
	try{
		xmlhttp=new XMLHttpRequest();
	}
	catch(e)	{		
		try{			
			xmlhttp= new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch(e){
			try{
			xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
			}
			catch(e1){
				xmlhttp=false;
			}
		}
	}

	return xmlhttp;
}

function getLocations(selectid, hotelId)
{
   var strURL="_getLocations.php?id="+hotelId+"&section="+selectid;
   var req = getXMLHTTP();
   if (req)
   {
     req.onreadystatechange = function()
     {
      if (req.readyState == 4)
      {
 // only if "OK"
 if (req.status == 200)
         {
    document.getElementById('locations'+selectid).innerHTML=req.responseText;
 } else {
   	   alert("There was a problem while using XMLHTTP:\n" + req.statusText);
 }
       }
      }
   req.open("GET", strURL, true);
   req.send(null);
   }
}
</script>

Link to comment
https://forums.phpfreaks.com/topic/209972-post-data-not-being-sent/
Share on other sites

Do some debugging. In your php file print the values of the GET variables i.e

print $_GET['id']."<br />".$_GET['section'];

This should be diplayed within

<span id="locations1"></span>

 

Use Firefoxs' error console incase there are any Javascript errors.

Check the JS is running. Use a simple alert() to show that the request has been made i.e

if (req.status == 200)  {
       alert('completed');
}

Check that the request URL is the correct path. I would usuall use the full url as opposed to just the file filename.

var strURL="_getLocations.php?id="+hotelId+"&section="+selectid

I've sorted it.

 

It was one of those errors that takes ages to find and when you find it you realise it was so simple.

 

I was populating the value of each drop down element with the id of the database record. The only problem was that I wasn't selecting the id field in my query so it wasn't recognising a value.

 

Thanks for your help anyway. :)

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.