1. I need to Modify the doSubmit() function so that it identifies the specific t
ID: 3706067 • Letter: 1
Question
1. I need to Modify the doSubmit() function so that it identifies the specific text field that is missing data (such as Name is missing, Address is missing, etc.)
2. Create a similar web page but for a computer retailer ,
In addition to verifying text fields (Name, Address, City, State, etc.), your web site must allow one and only one CPU is select, one and only RAM choice is selected, and one and only one HDD is selected.
the web site doesn't care about how many optional software products are chosen.
Customize each message with "Please enter a customer name. Thanks, xyz, LLC."
<html>
<head>
<title>HTML and JavaScript</title>
<script>
function doClear()
{
document.PizzaForm.customer.value = "";
document.PizzaForm.address.value = "";
document.PizzaForm.city.value = "";
document.PizzaForm.state.selectedIndex = 0;
document.PizzaForm.zip.value = "";
document.PizzaForm.phone.value = "";
document.PizzaForm.email.value = "";
document.PizzaForm.sizes[0].checked = false;
document.PizzaForm.sizes[1].checked = false;
document.PizzaForm.sizes[2].checked = false;
document.PizzaForm.toppings[0].checked = false;
document.PizzaForm.toppings[1].checked = false;
document.PizzaForm.toppings[2].checked = false;
document.PizzaForm.toppings[3].checked = false;
document.PizzaForm.toppings[4].checked = false;
document.PizzaForm.toppings[5].checked = false;
document.PizzaForm.toppings[6].checked = false;
document.PizzaForm.toppings[7].checked = false; // new
return;
}
function doSubmit()
{
if (validateText() == false) // delete
{
alert("Required data missing in Step 1");
return;
}
if (validateRadio() == false)
{
alert("User must select a size.");
return;
}
if(validateToppings()< 1)
{
alert("Topping must be between 1 - 3.");
return
}
if(validateToppings()> 3)
{
alert("Topping must be between 1 - 3.");
return;
}
alert("Your pizza order has been submitted.");
return;
}
function validateText()
{
var customer = document.PizzaForm.customer.value;
if (customer.length == 0) return false;
var address = document.PizzaForm.address.value;
if (address.length == 0) return false;
var city = document.PizzaForm.city.value;
if (city.length == 0) return false;
var state = document.PizzaForm.state.selectedIndex;
if (state == 0) return false;
var phone = document.PizzaForm.phone.value;
if (phone.length == 0) return false;
return true;
}
function validateRadio()
{
if (document.PizzaForm.sizes[0].checked) return true;
if (document.PizzaForm.sizes[1].checked) return true;
if (document.PizzaForm.sizes[2].checked) return true;
return false;
}
function validateToppings()
{
var toppings = 0;
var i
for(i=0; i < document.PizzaForm.toppings.length; i++)
if(document.PizzaForm.toppings[i].checked==true)
toppings +=1
return toppings;
}
</script>
</head>
<body>
<form name="PizzaForm">
<h1>Fausto Arce Pizza Palace</h1>
<p>
<h4>Step 1: Enter your name, address, and phone number:</h4>
<font face="Courier New">
Name: <input name="customer" size="50" type="text"><br>
Address: <input name="address" size="50" type="text"><br>
City: <input name="city" size="15" type="text">
State:
<select name="state">
<option value="0"></option>
<option value="1">AZ</option>
<option value="2">CO</option>
<option value="3">NM</option>
<option value="4">UT</option>
</select>
Zip: <input name="zip" size="5" type="text"><br>
Phone: <input name="phone" size="50" type="text"><br>
Email: <input name="Email" size="50" type="text"><br> // new
</font>
</p>
<p>
<h4>Step 2: Select the size of pizza you want:</h4>
<font face="Courier New">
<input name="sizes" type="radio">Small
<input name="sizes" type="radio">Medium
<input name="sizes" type="radio">Large
<input name="sizes" type="radio">Jumbo<br> // added
</font>
</p>
<p>
<h4>Step 3: Select the pizza toppings you want:</h4>
<font face="Courier New">
<input name="toppings" type="checkbox">Pepperoni
<input name="toppings" type="checkbox">Canadian Bacon
<input name="toppings" type="checkbox">Sausage<br>
<input name="toppings" type="checkbox">Mushrooms
<input name="toppings" type="checkbox">Pineapple
<input name="toppings" type="checkbox">Black Olives<br>
<input name="toppings" type="checkbox">Green Peppers // added
<input name="toppings" type="checkbox">Extra Cheese<br> // added
</font>
</p>
<input type="button" value="Submit Order">
<input type="button" value="Clear Entries">
</form>
</body>
</html>
Explanation / Answer
//Hi i have removed alert statement from dosubmit() function.
Placed alert message in validatetext() function. Hopefully this helps.
function doSubmit()
{
if (validateText() == false) // delete
{
// alert("Required data missing in Step 1");
return;
}
if (validateRadio() == false)
{
alert("User must select a size.");
return;
}
if(validateToppings()< 1)
{
alert("Topping must be between 1 - 3.");
return
}
if(validateToppings()> 3)
{
alert("Topping must be between 1 - 3.");
return;
}
alert("Your pizza order has been submitted.");
return;
}
function validateText()
{
var customer = document.PizzaForm.customer.value;
if (customer.length == 0) {
alert("Name is missing" ) ;
return false;}
var address = document.PizzaForm.address.value;
if (address.length == 0){
alert("Please enter valid address" ) ;
return false;}
var city = document.PizzaForm.city.value;
if (city.length == 0){
alert("Please enter city" ) ;
return false;}
var state = document.PizzaForm.state.selectedIndex;
if (state == 0){
alert("Please enter state" ) ;
return false;}
var phone = document.PizzaForm.phone.value;
if (phone.length == 0) {
alert("phone is missing") ;
return false;}
return true;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.