Forum Moderators: open
- John
Variable of HTTP queries/post parameters
function my_func1() {
var parameters = 'formis=' + encodeURI(document.getElementById('formis').value) +
'®_username=' + encodeURI(document.getElementById('reg_username').value) +
'®_username_base=' + username_base +
'®_password=' + encodeURI(document.getElementById('reg_password').value) +
'®_passwordconfirm=' + encodeURI(document.getElementById('reg_passwordconfirm').value) +
'®_email=' + encodeURI(document.getElementById('reg_email').value) +
'®_emailconfirm=' + encodeURI(document.getElementById('reg_emailconfirm').value);alert(ajax_post(this.parentNode, 'test_ajax.php', parameters));
}
AJAX Function
function ajax_post(obj, url, parameters)
{
var http_request = false;
if (window.XMLHttpRequest)
{
http_request = new XMLHttpRequest();
if (http_request.overrideMimeType) {http_request.overrideMimeType('text/html');} // set type accordingly to anticipated content type: http_request.overrideMimeType('text/xml');
}
else if (window.ActiveXObject) { // IE
try {
http_request = new ActiveXObject('Msxml2.XMLHTTP');
} catch (e) {
try {
http_request = new ActiveXObject('Microsoft.XMLHTTP');
} catch (e) {}
}
}
if (!http_request) {
alert('Cannot create XMLHTTP instance');
return false;
}
http_request.onreadystatechange = alertContents;
http_request.open('POST', url, false);
http_request.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
http_request.setRequestHeader('Content-length', parameters.length);
http_request.setRequestHeader('Connection', 'close');
http_request.send(parameters);
return http_request.responseText;
}
1. I have a form
2. With a drop where you select a country
3. From that selection another drop down appears for a city :
The city is displayed through :
<div id="txtHint">
4. then the user would fill in the rest of the form and press submit and the form would be inserted into a mysql database .
The problems :
1. Txthint is not allowing me to pass a variable
2. Post passes arrays which I dont need for a mysql post
I am doing onchange () in a drop down which calls the following function :
?php
$q=$_GET["q"];
$con = mysql_connect('localhost', 'malcolm', '');
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("tourz", $con);
$sql="SELECT * FROM city WHERE country = '".$q."'";
$result = mysql_query($sql);
echo "<SELECT NAME='myPrimarySelect' id='city' style='position: relative; width: 215px;' onChange=''>";
while($row = mysql_fetch_array($result))
{
print ("<option>" . $row['city'] . "</option>");
}
echo "</select>";
mysql_close($con);
?>
So for this function :
I choose America
I get a choice of
Washington , new york los angeles ect
However This data is displayed through
a <div id="txtHint">
Now i would like to take the data in the div id and process it to another form ?
That is where my problem lies.