mattspriggs28 Posted August 6, 2010 Share Posted August 6, 2010 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+"§ion="+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> Quote Link to comment https://forums.phpfreaks.com/topic/209972-post-data-not-being-sent/ Share on other sites More sharing options...
JonnoTheDev Posted August 6, 2010 Share Posted August 6, 2010 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+"§ion="+selectid Quote Link to comment https://forums.phpfreaks.com/topic/209972-post-data-not-being-sent/#findComment-1095991 Share on other sites More sharing options...
mattspriggs28 Posted August 9, 2010 Author Share Posted August 9, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/209972-post-data-not-being-sent/#findComment-1097019 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.