I have been losing hair on this one, never mind sleep !!!
I have a jquery script with 3 drop down boxes 1 ) province 2 ) city 3 ) suburb, when you select #1, the cities load, when you select a city, the suburbs load,
all is working 100%, but the problem is, when I try to save the city value via php $_POST, the value is empty, I have gone as far as trying to enter the returned value
into a hidden field to be submitted with the rest of the form, but to no avail.
I have an alert which does successfully return the value in the alert box, but applying it to a hidden field, stays empty!
please help me out, still very new to javascript & jquery.
the code is below :
the jqeury that returns the city values :
function getCity(countryId,stateId) {
$myvalue = document.getElementById('cities').value;
document.getElementById('mycitynew').value = $myvalue; //(document.getElementById('cities').value);
alert(document.getElementById('cities').value); // test to see if value is there !
var strURL="findCity2.php?country="+countryId+"&state="+stateId;
var req = getXMLHTTP();
if (req) {
req.onreadystatechange = function() {
if (req.readyState == 4) {
// only if "OK"
if (req.status == 200) {
document.getElementById('suburbdiv').innerHTML=req.responseText;
document.getElementById('mycitynew').value = $myvalue;
} else {
alert("There was a problem while using XMLHTTP:\
" + req.statusText);
}
}
}
req.open("GET", strURL, true);
req.send(null);
}
}
above you will see I try to enter the jquery value of cities into the hidden field ‘mycitynew’, the alert works, but the value of hidden field stays empty.
my hidden field ( that stays empty, no matter what I try! )
<input type="hidden" id="mycitynew" name="mycitynew" value=""/>