About Food store application

+2 Likhit Vivek Chirumamilla · April 1, 2015
I wrote the whole code of the first application - online restaurant in three files foodstore.html, foodstore.php and foodstore.js.

But when I open foodstore.html I am not getting the 'under input'. Basically, I am entering a food in the input and nothing is happening. Where did I go wrong?

Post a Reply

Replies

Oldest  Newest  Rating
0 Sho Carter · April 3, 2015
<div id=uderInput" /> supposed to be this:

<div id="underInput">
</div>
0 Likhit Vivek Chirumamilla · April 3, 2015








The Chuff Bucket
Enter the food you want to order:



0 Likhit Vivek Chirumamilla · April 3, 2015
<!DOCTYPE html>

<html>
<head>
<script type="text/javascript" src="lec3.js" ></script>
</head>
<body onload="process()">
<h3>The Chuff Bucket</h3>
Enter the food you want to order:
<input type="text" id="userInput" />
<div id="underInput" />
</body>
</html>
0 Likhit Vivek Chirumamilla · April 3, 2015
<?php
header('Content-type: text/xml');
echo '<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>';

echo '<response>';
$food = $_GET['food'];
$foodArray = array('tuna','bacon','beef','loaf','ham');
if(in_array($food,$foodArray))
echo 'We do have '.$food.'!';
elseif($food == '')
echo 'Enter a food you idiot';
else
echo 'Sorry punk we dont sell no '.$food.'!';

echo '</response>';
?>



This is my php file
0 Sho Carter · April 3, 2015
i can't see the html file
0 Likhit Vivek Chirumamilla · April 1, 2015
These are my three files......... I didn't write anything else

foodstore.html











The Chuff Bucket
Enter the food you want to order:




foodstore.php





lec3.js



var xmlHttp = createXmlHttpRequestObejct();

function createXmlHttpRequestObject(){
var xmlHttp;

if(window.ActiveXObject){
try{
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}catch(e){
xmlHttp = fasle;
}
}else{
try{
xmlHttp = new XMLHttpRequest();
}catch(e){
xmlHttp = false;
}
}

if(!xmlHttp)
alert("cant create that object hoss!");
else
return xmlHttp;
}

function process(){
if(xmlHttp.readyState==0||xmlHttp.readyState==4){
food = encodeURIComponent(document.getElementById("userInput").value);
xmlHttp.open("GET", "lec3.php?food=" + food, true);
xmlHttp.onreadystatechange = handleServerResponse;
xmlHttp.send(null);
}else{
setTimeout('process()', 1000);
}
}

function handleServerResponse(){
if(xmlHttp.readyState==4){
if(xmlHttp.status==200){
xmlResponse = xmlHttp.responseXML;
xmlDocumentElement = xmlResponse.documentElement;
message = xmlDocumentElement.firstChild.data;
document.getElementById("underInput").innerHTML = '' + message + '';
setTimeout('process()',1000);
}else{
alert('Something went wrong!');
}
}
}

I think I am running it wrong....... I am opening only foodstore.html and checking it in google chrome

I think there is something else I need to do, which I cant understand.
0 Sho Carter · April 1, 2015
Can we please see sample code?
Have you wrapped your input fields in a <form> tag? 
Have you entered the form "method"?
  • 1

Javascript

107,163 followers
About

A scripting language that is added to standard HTML to create interactive effects, apps, games for the browser.

Links
Moderators