473,326 Members | 2,175 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Not getting correct return values from Ajax script

anyone have any idea why i am not getting any return values? it will return the words just not the numbers?

HTML
[HTML]
<HTML>
<head>
<title>Zellers Carpeting Cost Estimate</title>
</head>

<script>

var http = createRequestObject();

function createRequestObject() {

var ro;
var browser = navigator.appName;
if(browser == "Microsoft Internet Explorer"){
ro = new ActiveXObject("Microsoft.XMLHTTP");
}else{
ro = new XMLHttpRequest();
}
return ro;
}

function CarpetJob(argW,argL, argType, argPad, argReq) {

var width;
var length;
var carpet;
var padding;
var install;

width=document.carpetform.width.value;
length=document.carpetform.length.value;
carpet=document.carpetform.carpet.value;
padding=document.carpetform.padding.value;
install=document.carpetform.install.value;

http.open('get', "carpet.php?width=" + argW +"&length="+ argL +"&carpet=" + argType +"&padding="+ argPad +"&install="+ argReq);
http.onreadystatechange = handleResponse;
http.send(null);
}

function handleResponse() {

if(http.readyState == 4){

document.getElementById("results").innerHTML = http.responseText;
}
}

</script>
<body>
<div id="banner">
<h1>Zellers Carpeting</h1>
<h2>Cost Estimate</h3>
</div>

<div class="instructions">Enter all the relevant parameters and click submit for an estimate of the cost of carpeting your room</div>

<div id="userinput">
<form method="get" name="carpetform" action="#">
<table>
<tr>
<td>Room Dimensions (in ft):</td>
<td><input type="text" name="width"> x <input type="text" name="length"></td>
</tr>
<tr>
<td ><strong>Type of Carpet:</strong></td>
<td>
<select name="carpet">
<option value="">Choose Carpet Type</option>
<option value="B">Budget</option>
<option value="S">Standard</option> <option value="P">Premium</option>
</select>
</td>
</tr>
<tr>
<td ><strong>Type of Padding:</strong></td>
<td>

<select name="padding">
<option value="">Choose Padding</option>
<option value="S">Standard</option>
<option value="P">Premium</option>
</select>

</td>
</tr>
<tr>
<td><strong>Installation Required:</strong></td>

<td>Yes<input type=radio name="install" value=y>&nbsp;&nbsp;&nbsp;No

<input type=radio name="install" value=n></td>
</tr>
<tr>
<td align=center colspan=2><input type="button" value="Submit" onclick="CarpetJob();"></td>
</tr>
</table>
</form>
</div>

<div id="results">

</div>
</body>

</HTML>


PHP PAGE

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-Transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">

<head>

<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />

<title>Carpet</title>

<link type="text/css" rel="stylesheet" href="carpet.css" />
</head>

<body>
<h1>The Summary of Your Carpet Order:</h1>

<div id="all">

<?php

$W=$_GET['width'];

$L=$_GET['length'];

$carpet=$_GET['carpet'];

$padding=$_GET['padding'];

$install=$_GET['install'];


//The formula for 20% more

$area= $W * $L;

$extra=$area * .20 + $area;


?>

<br />
<br />

<?php

//The carpet price

if($carpet=="B"){
$c="1.00";

}

if($carpet=="S"){
$c="1.50";
}

if($carpet=="P"){
$c="2.00";
}

$carpetCost= $c * $extra;

print ("Your $area ft. of Carpet will cost $$carpetCost");
?>

<br />
<br />

<?php
//Padding Cost

if($padding=="S"){
$cp=.35;
}

if($padding=="P"){
$cp=.50;
}

$cPadding=$cp * $extra;

print ("Your Padding will cost $$cPadding")
?>

<br />
<br />

<?php

//The Install cost

if($install=="n"){
$in=.00;
}

if($install=="y"){
$in=2.00;
}

$installCost=$in * $extra;

print ("Your install cost will be $$installCost");

?>

<br />
<br />

<?php

$salesTax=($carpetCost+$cPadding)*.07;

print ("Your Sales Tax will be $$salesTax");
?>

<br />
<br />

<?php

$totalCost=$carpetCost+$cPadding+$installCost+$sal esTax;

print ("Your Grand Total for your carpet is $$totalCost");
?>

<br />
<br />
<?php

if ($carpet=="B"){

print (' <img src="budget.jpg" alt="Budget Carpet"/>' );
}

if ($carpet=="S"){

print ('<img src="standard.jpg" alt="Standard Carpet"/>');

}

if ($carpet=="P"){

print ('<img src="premium.jpg" alt="Premium Carpet"/>');

}

?>

<?php

if ($install=="y"){

print ('<img src="logo.jpg" alt="logo"/>');
}

if ($install=="n"){

}

?>
</div>

</body>

</html>[/HTML]
Apr 9 '08 #1
12 1799
sorry to further clarify...

when i push submit it will return something like

the cost of your carpet is 0

the area is 0

it will get the php page, but not do the calculations...
Apr 9 '08 #2
acoder
16,027 Expert Mod 8TB
Since you're not passing the arguments to CarpetJob(), use the variables you've created within the function:
Expand|Select|Wrap|Line Numbers
  1. http.open('get', "carpet.php?width=" + width +"&length="+ length +"&carpet=" + carpet +"&padding="+ padding +"&install="+ install);
Apr 10 '08 #3
what values would i put in there?
Apr 14 '08 #4
I posted an earlier question asking about getting all 0's in my return values, could someone help me out with this problem...

HTML

[HTML]<HTML>
<head>
<title>Zellers Carpeting Cost Estimate</title>
</head>

<script>

var http = createRequestObject();

function createRequestObject() {

var ro;
var browser = navigator.appName;
if(browser == "Microsoft Internet Explorer"){
ro = new ActiveXObject("Microsoft.XMLHTTP");
}else{
ro = new XMLHttpRequest();
}
return ro;
}

function CarpetJob(argWidth, argLength, argType, argPad, argReq){
alert("****")

http.open('get', "carpet.php?Width=" +argWidth+"&length=" +argLength+"&carpet=" +argType+"&padding=" +argPad+"&install=" +argReq);
http.onreadystatechange = handleResponse;
http.send(null);
}

function handleResponse() {

if(http.readyState == 4){

document.getElementById("results").innerHTML = http.responseText;

}
}

</script>
<body>
<div id="banner">
<h1>Zellers Carpeting</h1>
<h2>Cost Estimate</h3>
</div>
<div class="instructions">Enter all the relevant parameters and click submit for an estimate
of the cost of carpeting your room</div>

<div id="userinput">
<form method="get" name="carpetform" action="#">
<table>
<tr>
<td>Room Dimensions (in ft):</td>

<td><input type="text" name="width"> x <input type="text" name="length"></td>
</tr>
<tr>
<td ><strong>Type of Carpet:</strong></td>
<td>
<select name="carpet">
<option value="">Choose Carpet Type</option>
<option value="B">Budget</option>
<option value="S">Standard</option>
<option value="P">Premium</option>
</select>
</td>
</tr>
<tr>
<td ><strong>Type of Padding:</strong></td>
<td>
<select name="padding">
<option value="">Choose Padding</option>
<option value="S">Standard</option>
<option value="P">Premium</option>
</select>
</td>
</tr>
<tr>
<td><strong>Installation Required:</strong></td>

<td>Yes<input type=radio name="install" value=y>&nbsp;&nbsp;&nbsp;No

<input type=radio name="install" value=n></td>
</tr>
<tr>
<td align=center colspan=2><input type="button" value="Submit" name="btnSubmit" onClick="CarpetJob(document.forms.carpetform.width .value, document.forms.carpetform.length.value, document.forms.carpetform.carpet.value, document.forms.carpetform.padding.value, document.forms.carpetform.install.value);"></td>
</tr>
</table>
</form>
</div>

<div id="results">

</div>
</body></HTML>
[/HTML]
PHP

[PHP]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-Transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">

<head>

<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />


<title>Carpet 7</title>

<link type="text/css" rel="stylesheet" href="carpet.css" />



</head>

<body>

<h1>The Summary of Your Carpet Order:</h1>

<div id="all">

<?php

$W=$_GET['width'];
$L=$_GET['length'];

$carpet=$_GET['carpet'];

$padding=$_GET['padding'];

$install=$_GET['install'];


//The formula for 20% more

$area= $W * $L;

$extra=$area * .20 + $area;


?>

<br />
<br />

<?php

//The carpet price

if($carpet=="B"){
$c="1.00";

}

if($carpet=="S"){
$c="1.50";
}

if($carpet=="P"){
$c="2.00";
}

$carpetCost= $c * $extra;

print ("Your $area ft. of Carpet will cost $$carpetCost");
?>

<br />
<br />

<?php


//Padding Cost

if($padding=="S"){
$cp=.35;
}

if($padding=="P"){
$cp=.50;
}

$cPadding=$cp * $extra;

print ("Your Padding will cost $$cPadding")


?>

<br />
<br />

<?php
//The Install cost

if($install=="n"){
$in=.00;
}

if($install=="y"){
$in=2.00;
}

$installCost=$in * $extra;

print ("Your install cost will be $$installCost");
?>

<br />
<br />

<?php

$salesTax=($carpetCost+$cPadding)*.07;

print ("Your Sales Tax will be $$salesTax");

?>

<br />
<br />

<?php

$totalCost=$carpetCost+$cPadding+$installCost+$sal esTax;

print ("Your Grand Total for your carpet is $$totalCost");
?>

<br />
<br />
<?php

if ($carpet=="B"){

print (' <img src="budget.jpg" alt="Budget Carpet"/>' );
}

if ($carpet=="S"){

print ('<img src="standard.jpg" alt="Standard Carpet"/>');

}

if ($carpet=="P"){

print ('<img src="premium.jpg" alt="Premium Carpet"/>');

}

?>
<?php

if ($install=="y"){

print ('<img src="logo.jpg" alt="logo"/>');
}

if ($install=="n"){
}

?>
</div>

</body>

</html>[/PHP]
Apr 14 '08 #5
acoder
16,027 Expert Mod 8TB
what values would i put in there?
I'm not sure what you mean. You've already got the values - see lines 30-34 in your code.
Apr 15 '08 #6
acoder
16,027 Expert Mod 8TB
I posted an earlier question...
Then there was no need to double-post. Please keep all posts relating to one problem in one thread.

Also, remember to use [code] tags when posting code. Thanks!
Apr 15 '08 #7
Then there was no need to double-post. Please keep all posts relating to one problem in one thread.

Also, remember to use [code] tags when posting code. Thanks!
sorry, but i really dont know how to do this crap, i just need someone to show me how to do it so i can learn from it... i know how to test the sever side code by rebuilding the query string, but it just doesnt work. I also test with alert boxes to make sure im hitting the function...

help me out
Apr 15 '08 #8
acoder
16,027 Expert Mod 8TB
First check that the PHP script works without Ajax, i.e. when you submit the form to that script. Once you have that working, then one problem I can see with your current script is that to get the radio button, you need to check that the checked property of the radio button is checked. For that, you need to loop over the radio buttons. Let me know if you want a quick example.
Apr 15 '08 #9
yea i could use an example of that... I just dont understand how it is returning 0's when the query string works if i test it...
Apr 15 '08 #10
acoder
16,027 Expert Mod 8TB
Expand|Select|Wrap|Line Numbers
  1. var radio = document.forms["carpetform"].elements["install"];
  2. for (i = 0; i < radio.length; i++) { 
  3.   if (radio[i].checked) {
  4.     val = radio[i].value;
  5.     break;
  6.   }
  7. }// val contains the radio value...
Apr 16 '08 #11
Expand|Select|Wrap|Line Numbers
  1. var radio = document.forms["carpetform"].elements["install"];
  2. for (i = 0; i < radio.length; i++) { 
  3.   if (radio[i].checked) {
  4.     val = radio[i].value;
  5.     break;
  6.   }
  7. }// val contains the radio value...

and that would go in my function right?
Apr 16 '08 #12
acoder
16,027 Expert Mod 8TB
Yes, and val would replace argReq (or you could call it argReq instead of val).
Apr 17 '08 #13

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Bhavin G | last post by:
Hi there , I am pretty new at javascripting and i am having this huge problem. I am using asp.net and C# webapplication. In my asp.net aspx file I have a place holder for taking an html table...
1
by: kamleshsharmadts | last post by:
I am using Ajax with struts in web application. from jsp i am calling a function of ajax.js onclick of a button. code of that call function which calling from jsp given as below:- ...
4
by: d3vkit | last post by:
I have a form on my page, and some javascript which uses ajax to submit the form, and then opens the new page in a div using ajax so there is no refresh. This works fine. But the problem is this: all...
6
by: sgottenyc | last post by:
Hello, If you could assist me with the following situation, I would be very grateful. I have a table of data retrieved from database displayed on screen. To each row of data, I have added...
2
by: Nathan Sokalski | last post by:
I am moving my website from my machine to my webhost, and need some help with what extra files I need to include due to the fact that I used AJAX in my site. Everything on the site is obviously...
1
by: msg2ajay | last post by:
hello, i am very new to Ajax i have tried an example but it showing some error can anybady tell me where i am doing mistake... my coding is as follows ajax.html: ----------- ...
15
by: JohnDriver | last post by:
Hello I am learning Ajax and I am following the tutorials found but for some reason, my code is not working. I think I am missing something in the code that I am posting below. Please have a look...
21
vikas251074
by: vikas251074 | last post by:
I am getting error while entry in userid field. When user enter his user id, an event is fired immediately and user id is verified using AJAX method. But I am getting error 'Object doesn't support...
1
by: raghuvendra | last post by:
Hi I have a jsp page with 4 columns: namely Category name , Category order, Input field and a submit button. All these are aligned in a row. And Each Category Name has its corresponding Category...
9
Catalyst159
by: Catalyst159 | last post by:
I have a form which is used to calculate residential Floor Area Ratio (FAR). The form is structured into seven parts as follows: Part A: Maximum FAR and Floor Area: Part B: Gross Floor Area of...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.