O'Reilly Forums: Address Field In Breakneckpizza App - O'Reilly Forums

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

Address Field In Breakneckpizza App shows entire PHP script

#1 User is offline   mmarkym 

  • Active Member
  • PipPip
  • Group: Members
  • Posts: 13
  • Joined: 12-February 11

Posted 12 February 2011 - 01:35 AM

Hi,

I've completed chapter two but when I run the onChange event in the BreakNeckPizza order form, when the phone field changes, it populates the address field with the entire php script, displayed.

Here is the code-

<!--
To change this template, choose Tools | Templates
and open the template in the editor.
-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Break Neck Pizza Delivery</title>
<link rel="stylesheet" type="text/css"
href="breakneck.css" media="screen" />
<script language="javascript" type="text/javascript">
var request = null;

try {
request = new XMLHttpRequest();
} catch (trymicrosoft) {
try {
request = new ActiveXObject("Msxml2.XMLHTTP");
} catch (othermicrosoft) {
try {
request = new ActiveXObject("Microsoft.XMLHTTP");
} catch (failed) {
request = null;
}
}
}

if (request == null)
alert("Error creating request object!");

function getCustomerInfo() {
var phone = document.getElementById("phone").value;
var url = "lookupCustomer.php?phone=" +
escape(phone);
url += "?PDummy=" + new Date().getTime();
request.open("GET", url, true);
request.onreadystatechange = updatePage;
request.send(null);
}

function updatePage() {

if (request.readyState == 4)
{
if (request.status == 200)
{

/* Get the response from the server */
var customerAddress = request.responseText;

/* Update the HTML web form */
document.getElementById("address").value =
customerAddress;
}
}
}
</script>
</head>

<body onLoad="document.forms[0].reset();">
<p><img src="breakneck-logo.gif" alt="Break Neck Pizza" /></p>
<form method="POST" action="placeOrder.php">
<p>Enter your phone number:
<input type="text" size="14"
name="phone" id="phone" onChange="getCustomerInfo();" />
</p>
<p>Type your order in here:</p>
<p><textarea name="order" id="order"
rows="6" cols="50"></textarea></p>
<p>Your order will be delivered to:</p>
<p><textarea name="address" id="address"
rows="4" cols="50"></textarea></p>
<p><input type="submit" id="submit"
value="Order Pizza" /></p>
</form>
</body>
</html>


0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

2 User(s) are reading this topic
0 members, 2 guests, 0 anonymous users