Kennelbloke
Technical User
Hi folks
Using PHP/MYSQL and some Javascript for a site, where at some stage, people will fill out an address. I am trying to return the postal code automatically based upon the Suburb they select from a dropdown. The postal code is stored with the suburb in the database.
My problem is that is not returning a value.
The form to get the postcode is (don't worry about the variables)
The above page works fine and returns the correct Postcode with no other header or body text on the page.
The javascript code to do is
I have tried moving to id="Postcode" to the div statement and move it to the input statement but not getting any returned value.
For some reason I did have it returning a value at some stage of my playing around but it was in the div area and so was not saved when the form was saved.
Javascript is not my thing so I'm unsure what is going on.
Can someone please point me in the right direction.
Using PHP/MYSQL and some Javascript for a site, where at some stage, people will fill out an address. I am trying to return the postal code automatically based upon the Suburb they select from a dropdown. The postal code is stored with the suburb in the database.
My problem is that is not returning a value.
HTML:
...
div class="rfa_edit_data"><select name="suburb_id" id="suburb_id" onchange="PCodeGrab('pcode_get.php?ssid='+this.value)">
<option value="0"></option>
<option value="2">Abbotsham - Central Coast Council</option>
<option value="3">Aberdeen - Devonport City Council</option>
...etc
<div class="rfa_edit_data" id="postcode"><input name="postcode" type="text" size="10" value=""></div>
The form to get the postcode is (don't worry about the variables)
PHP:
<?php
include('main_nomenu_noheader.inc');
if (n2z($_GET['ssid'],0) > 0) {
$pcodeSQL = "SELECT postcode FROM ".$db_base."_suburbs.suburbs WHERE id = ".$_GET['ssid'];
}
$pcresult = mysqli_query($db, $pcodeSQL);
if ($strError = mysqli_error($db)) {
echo '<p>'.$strError.'<br />'.$pcodeSQL.'</p>';
} else {
while($pcrow = mysqli_fetch_array($pcresult)) {
$getpcode = $pcrow["postcode"];
echo $getpcode;
}
}
?>
The above page works fine and returns the correct Postcode with no other header or body text on the page.
The javascript code to do is
JavaScript:
function PCodeGrab(strURL) {
var req = CreateXmlHttpObject();
if (req) {
req.onreadystatechange = function() {
if (req.readyState == 4) {
if (req.status == 200) {
document.getElementById('postcode').innerHTML=req.responseText;
} else {
alert("There was a problem while using XMLHTTP:\n");
}
}
}
req.open("GET", strURL, true);
req.send(null);
}
}
I have tried moving to id="Postcode" to the div statement and move it to the input statement but not getting any returned value.
For some reason I did have it returning a value at some stage of my playing around but it was in the div area and so was not saved when the form was saved.
Javascript is not my thing so I'm unsure what is going on.
Can someone please point me in the right direction.