Revisit the table you calculated in unit 4. Recall that this script uses client-
ID: 2246820 • Letter: R
Question
Revisit the table you calculated in unit 4. Recall that this script uses client-side JavaScript. The way it works, the web server sends both the XHTML and the JavaScript to the client's web browser. The browser then executes the JavaScript to produce additional XHTML, which it then renders on the screen.
Rewrite the program to use server-side PHP instead. The syntax of PHP is similar to that of JavaScript; keep in mind the following differences:
PHP uses the print function instead of JavaScript's document.write function.
PHP prefixes a dollar sign ($) on every variable name.
PHP encloses its code in <?php and ?> tags, where JavaScript uses <script> and </script?>.
JavaScript and PHP provide different function libraries. For example, the JavaScript Math.round()and the PHP round() functions work differently.
JavaScript uses "+" to concatenate strings while PHP substitutes values for variables inside a string. With PHP, you cannot calculate and concatenate in one statement.
Submit your pages to the W3C validator (http://validator.w3.org/) and correct all errors.
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
JS CODE from Unit 4
<!DOCTYPE HTML>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link rel="stylesheet" type= "text/css" href="style.css">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>Bears Memorabilia Calculator</title>
<script type="text/javascript" >
function checkValidation()
{
var decimal= (/[d]+(.[d]+)?/);
if(element_1.value.match(decimal))
{
if(element_2.value.match(decimal))
{
if(element_3.value.match(decimal))
{
display();
return true;
}
else
{
alert('Any alphabets or special character other than . (dot) ')
return false;
return false;
}
}
else
{ alert('Any alphabets or special character other than . (dot) ')
return false;
return false;
}
}
else
{
alert('Any alphabets or special character other than . (dot) ')
return false;
}
}
function display()
{
var value1 = document.getElementById("element_1").value;
var value2 = document.getElementById("element_2").value;
var value3 = document.getElementById("element_3").value;
var value4 =+value1 + +value2 + +value3;
alert("The total sum is "+value4)
}
</script>
</head>
<body id="main_body" >
<div id="form_container">
<h1><a>Bears Memorabilia</a></h1>
<form id="form_642363" class="appnitro" method="post" >
<div class="form_description">
<h2>Total Cost Calculator</h2>
<h3><a href="index.htm">Home Page</a></h3>
</div>
<ul >
<li id="li_1" >
<label class="description" for="element_1">Input Product Total </label>
<div>
<input id="element_1" name="element_1" class="element text medium" type="text" maxlength="255" value=""/>
</div>
</li> <li id="li_2" >
<label class="description" for="element_2">Input Sales Tax </label>
<div>
<input id="element_2" name="element_2" class="element text medium" type="text" maxlength="255" value=""/>
</div>
</li> <li id="li_3" >
<label class="description" for="element_3">Input Shipping Costs </label>
<div>
<input id="element_3" name="element_3" class="element text medium" type="text" maxlength="255" value=""/>
</div>
</li>
<li>
<input id="saveForm" class="button_text" type="submit" name="submit" value="Submit" />
</li>
</ul>
</form>
</div>
</body>
</html>
//Browser results when I enter data and hit submit; need PHP to do the same
Fried S PhotoReflect ::: Apps , Dashboard! Credit K e) Best Chicago Bears Memorabilia Total Cost Calculator Home Page This page says: The total sum is 160 OK Input Product Tota 150 Tax Input Sales 5 Input Shipping Costs 5 SubmitExplanation / Answer
Hi..Please find the changes in the below onr
JS CODE from Unit 4
<!DOCTYPE HTML>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link rel="stylesheet" type= "text/css" href="style.css">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>Bears Memorabilia Calculator</title>
<script type="text/javascript" >
function checkValidation()
{
var decimal= (/[d]+(.[d]+)?/);
if(element_1.value.match(decimal))
{
if(element_2.value.match(decimal))
{
if(element_3.value.match(decimal))
{
display();
return true;
}
else
{
alert('Any alphabets or special character other than . (dot) ')
return false;
return false;
}
}
else
{ alert('Any alphabets or special character other than . (dot) ')
return false;
return false;
}
}
else
{
alert('Any alphabets or special character other than . (dot) ')
return false;
}
}
function display()
{
var value1 = documnt.getElementById("element_1").value;
var value2 = documnt.getElementById("element_2").value;
var value3 = documnt.getElementById("element_3").value;
var value4 =+value1 + +value2 + +value3;
alert("The total sum is "+value4)
}
</script>
</head>
<body id="main_body" >
<div id="form_container">
<h1><a>Bears Memorabilia</a></h1>
<form id="form_642363" class="appnitro" method="post" >
<div class="form_description">
<h2>Total Cost Calculator</h2>
<h3><a href="index.htm">Home Page</a></h3>
</div>
<ul >
<li id="li_1" >
<label class="description" for="element_1">Input Product Total </label>
<div>
<input id="element_1" name="element_1" class="element text medium" type="text" maxlength="255" value=""/>
</div>
</li> <li id="li_2" >
<label class="description" for="element_2">Input Sales Tax </label>
<div>
<input id="element_2" name="element_2" class="element text medium" type="text" maxlength="255" value=""/>
</div>
</li> <li id="li_3" >
<label class="description" for="element_3">Input Shipping Costs </label>
<div>
<input id="element_3" name="element_3" class="element text medium" type="text" maxlength="255" value=""/>
</div>
</li>
<li>
<input id="saveForm" class="button_text" type="submit" name="submit" value="Submit" />
</li>
</ul>
</form>
</div>
</body>
</html>
thanks
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.