Description: during registration or shopping cart checkout, you need to fill in your personal data. This step can be concise. We only need to fill in the zip code for the guests and then follow the zip code, the database automatically retrieves the corresponding province, city, and other address information.
This not only reduces customer input, increases customer experience, but also reduces data input errors.
Implementation:
HTML
Enter A United States Zipcode, Then Tab
Enter Zipcode: |
name="zipcode" onBlur="sndReq(this.value);"/> |
City: |
|
State: |
|
|
The above is the customer input page, and the following is the server processing page 'zipcode. php
$dbuser = 'root'; $dbpass = '111111'; $cn = mysql_connect("localhost", $dbuser, $dbpass); $db = mysql_select_db("ajax"); $sql = "select city, state from zipcodes where zipcode = " . $_REQUEST['zip']; $rs = mysql_query($sql); $row = mysql_fetch_array($rs); echo $row['city'] . "|" . $row['state']; mysql_close($cn); ?>
|
After the customer enters a POSTCODE, zipcode. php receives it, extracts the corresponding data from the data table, and then returns it to the client in a certain format. Here, it is separated by | ). Finally, the client receives the returned information and displays it on the page.
if(response.indexOf('|' != -1)) { update = response.split('|'); document.getElementById("city").value = update[0]; document.getElementById("state").value = update[1]; }
|
Final:
(