/    Sign up×
Community /Pin to ProfileBookmark

Form Validation

I am having a problem doing these following instructions:

  • 1.

    [COLOR=Yellow]Add code for the “Save Pizza Details” button: This button should store the pizza details into the first available set of Hidden fields before clearing out the Toppings, Specialty Pizza, Crust and Special Instructions input items. This button should not affect values in the Name, Address or Phone fields. If all 3 sets of hidden fields have values, this button should not change any values on the form, but should Alert the user that 3 pizzas have been saved and let the user know he should click the “Order Pizza” button to submit his order.

  • 2.

    Before allowing the form to be submitted to your email address, verify that at least 1 pizza details have been stored into the hidden fields.[/COLOR]Here is the JavaScript code:

  • [COLOR=Magenta]<script language=”JavaScript”>

    var Pizza1=””,Pizza=””,Pizza3=””;
    var Name=””,Phone=””,Address=””;

    function checkMandatory()
    {
    //mandatory fields
    var Name=document.getElementById(“Name_Field”).value;
    var Address=document.getElementById(“Address_Field”).value;
    var Phone=document.getElementById(“Phone_Field”).value;

    if(Name.length==0)
    {
    alert(“Please enter your name”);

    }
    if (Address.length==0)
    {
    alert(“Please enter your address”);

    }
    if(Phone.length==0&&Phone.length!=7)
    {
    alert(“Please enter your phone number correctly”);

    }
    }
    function SavePizzaDetails()
    {
    var Toppings=false;
    var Specialty=false;
    var holdPizza=’size=’;
    for(i=0; i < document.forms[0].toppings.length;i++)
    {
    if(document.forms[0].toppings[i].checked==true)
    {
    Toppings=true;
    holdPizza+= ” + document.forms[0].toppings[i].value;

    }//end of if
    if(Toppings)
    {
    holdPizza+=”;
    //start loop with 1 so none is skipped

    for(i=0;i <document.forms[0].Specialty.options.length;i++)
    {

    if(document.forms[0].Specialty.options[i].selected)
    {
    Specialty=true;
    holdPizza+=” + document.forms[0].Specialty.options[i].text;
    }//end of if statement
    }//end of for loop

    }// end of second if

    //start loop with 1 so that None is skipped.
    for(i=1;i<document.forms[0].Specialty.options.length;i++)
    {
    if(document.forms[0].Specialty.options[i].selected)
    {
    // variables
    Specialty=true;
    holdPizza+=”+ document.forms[0].Specialty.options[i].text;

    }// end of if

    }//end of second for loop

    }//end of 3rd for loop
    if(Specialty)
    {
    holdPizza+=”;
    //either toppings should be choosen OR a specialty pizza selected, not both;

    if(Specialty&&Toppings)
    {
    holdPizza=”;//erase stored Pizza Details
    Validation=true;
    alert(“Sorry, you are only able to choose toppings OR Specialty for Pizzann”+ “Please Try again”);
    }// end of Specialty && Toppings if

    }//end of Specialty if statement

    }// end of Save Pizza Details Function

    //function reset
    function Reset()
    {
    document.forms[0].reset();

    window.document.getElementById(“Name_Field”).value=Name;
    window.document.getElememntById(“Phone_Field”).value=Phone;
    window.document.getElementById(“Address_Field”).value=Address;

    }

    function DisplayForm()
    {
    alert(“Pizza1=” + document.forms[0].Pizza1.value + “/n”);
    {
    alert(“Click save Pizza Details before ordering Pizza!”);
    //return false;}
    //else
    //return true;
    }

    }
    </script>
    [/COLOR]

    Here is the HTML code:

    <title>Ordering Pizza</title>
    <meta http-equiv=”Content-Type” content=”text/html; charset=iso-8859-1″>
    </head>
    <body>
    <p>
    <form method=”post” >
    <p><font size=”+4″><strong><font color=”#000000″>Ordering Pizza </font><font size=”+4″><strong><font color=”#000000″><img src=”file:///E|/pizzahut.gif” width=”163″ height=”134″></font></strong></font></strong></font></p>
    <p>Name:
    <input type=”text” size=”20″ maxlength=”50″ id=”this.Name_Field” ></p>
    <p>Address:
    <input type=”text” size=”20″ maxlength=”50″ id=”Address_Field”></p>
    <p>Phone:
    <input type=”text” size=”20″ maxlength=”50″ id=”Phone_Field”>
    <br>
    <p><input name=”Pizza1″ type=”hidden” id=”Pizza1″></p>
    <p><input name=”Pizza2″ type=”hidden” id=”Pizza2″></p>
    <p><input name=”Pizza3″ type=”hidden” id=”Pizza3″></p>
    </p>
    <p><strong>Size:</strong></p>
    <p>
    <input type=”radio” name=”size” value=”small” id=”Size_Small”>
    small
    <input type=”radio” name=”size” value”=medium” id=”Size_Medium”>
    medium
    <input type=”radio” name=”size” value=”large” id=”Size_Large”>
    large </p>
    <p><strong>Toppings:</strong>:<br>
    &nbsp;&nbsp;&nbsp;&nbsp;
    <input type=”checkbox” name=”toppings” id=”pepperoni”>
    pepperoni
    <input name=”toppings” type=”checkbox” id=”suasage”>
    sausage
    <input name=”toppings” type=”checkbox” id=”greenpeppers”>
    green peppers
    <input name=”toppings” type=”checkbox” id=”onions”>
    onions </p>
    <p>
    &nbsp;&nbsp;&nbsp;&nbsp; <input name=”toppings” type=”checkbox” id=”mushrooms”>
    mushrooms
    <input name=”toppings” type=”checkbox” id=”olives”>
    olives
    <input name=”toppings” type=”checkbox” id=”octapus”>
    octapus
    <input name=”toppings” type=”checkbox” id=”seaweed”>
    seaweed <strong>&nbsp;</strong></p>
    <p><strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;or Chooose Speciality Pizza
    <select name=”Specialty”>
    <option>None</option>
    <option>Pepper Steak</option>
    <option>Barbecue Pizza</option>
    </select>
    </strong></p>
    <p><strong>Crust:</strong><strong> </strong></p>
    <p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    <select name=”crust”>
    <option selected>Original</option>
    <option>Large</option>
    <option>XLarge</option>
    </select>
    </p>
    <input name=”Pizza1″ type=”hidden” id=”Pizza1″ >
    <input name=”Pizza2″ type=”hidden” id=”Pizza2″>
    <input name=”Pizza3″ type=”hidden” id=”Pizza3″>
    <p><strong> Special Instructions:</strong><br>
    &nbsp;
    <textarea ref=”message”></textarea>
    </p>
    <p>
    <input name=”order” type=”submit” value=”Order Pizza” onClick=”checkMandatory();”>
    <input name=”clear” type=”button” value=”Clear_Form” onClick=”Reset();”>
    <input name=”save” type=”button” value=”Save Pizza Details” onClick=”DisplayForm();”>
    </p>
    </form>
    </p>
    </body>
    </html>

    Please help me if you becuase it is something urgent I need to complete as soon as possible. The help will be appreciated. Thank you ?

    to post a comment
    JavaScript

    3 Comments(s)

    Copy linkTweet thisAlerts:
    @hevansauthorAug 18.2006 — I am having a problem doing these following instructions:

    Sorry for the Yellow colour for the instructions.

  • 1. Add code for the “Save Pizza Details” button: This button should store the pizza details into the first available set of Hidden fields before clearing out the Toppings, Specialty Pizza, Crust and Special Instructions input items. This button should not affect values in the Name, Address or Phone fields. If all 3 sets of hidden fields have values, this button should not change any values on the form, but should Alert the user that 3 pizzas have been saved and let the user know he should click the “Order Pizza” button to submit his order.


  • 2. Before allowing the form to be submitted to your email address, verify that at least 1 pizza details have been stored into the hidden fields.Here is the JavaScript code:


  • <script language="JavaScript">

    var Pizza1="",Pizza="",Pizza3="";

    var Name="",Phone="",Address="";

    function checkMandatory()

    {

    //mandatory fields

    var Name=document.getElementById("Name_Field").value;

    var Address=document.getElementById("Address_Field").value;

    var Phone=document.getElementById("Phone_Field").value;


    if(Name.length==0)

    {

    alert("Please enter your name");

    }

    if (Address.length==0)

    {

    alert("Please enter your address");

    }

    if(Phone.length==0&&Phone.length!=7)

    {

    alert("Please enter your phone number correctly");

    }

    }

    function SavePizzaDetails()

    {

    var Toppings=false;

    var Specialty=false;

    var holdPizza='size=';

    for(i=0; i < document.forms[0].toppings.length;i++)

    {

    if(document.forms[0].toppings[i].checked==true)

    {

    Toppings=true;

    holdPizza+= '' + document.forms[0].toppings[i].value;





    }//end of if

    if(Toppings)

    {

    holdPizza+='';

    //start loop with 1 so none is skipped



    for(i=0;i <document.forms[0].Specialty.options.length;i++)

    {



    if(document.forms[0].Specialty.options[i].selected)

    {

    Specialty=true;

    holdPizza+='' + document.forms[0].Specialty.options[i].text;

    }//end of if statement

    }//end of for loop



    }// end of second if



    //start loop with 1 so that None is skipped.

    for(i=1;i<document.forms[0].Specialty.options.length;i++)

    {

    if(document.forms[0].Specialty.options[i].selected)

    {

    // variables

    Specialty=true;

    holdPizza+=''+ document.forms[0].Specialty.options[i].text;



    }// end of if



    }//end of second for loop



    }//end of 3rd for loop

    if(Specialty)

    {

    holdPizza+='';

    //either toppings should be choosen OR a specialty pizza selected, not both;



    if(Specialty&&Toppings)

    {

    holdPizza='';//erase stored Pizza Details

    Validation=true;

    alert("Sorry, you are only able to choose toppings OR Specialty for Pizzann"+ "Please Try again");

    }// end of Specialty && Toppings if



    }//end of Specialty if statement



    }// end of Save Pizza Details Function





    //function reset

    function Reset()

    {

    document.forms[0].reset();



    window.document.getElementById("Name_Field").value=Name;

    window.document.getElememntById("Phone_Field").value=Phone;

    window.document.getElementById("Address_Field").value=Address;





    }









    function DisplayForm()

    {

    alert("Pizza1=" + document.forms[0].Pizza1.value + "/n");

    {

    alert("Click save Pizza Details before ordering Pizza!");

    //return false;}

    //else

    //return true;

    }





    }

    </script>



    Here is the HTML code:



    <title>Ordering Pizza</title>

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

    </head>

    <body>

    <p>

    <form method="post" >

    <p><font size="+4"><strong><font color="#000000">Ordering Pizza </font><font size="+4"><strong><font color="#000000"><img src="file:///E|/pizzahut.gif" width="163" height="134"></font></strong></font></strong></font></p>

    <p>Name:

    <input type="text" size="20" maxlength="50" id="this.Name_Field" ></p>

    <p>Address:

    <input type="text" size="20" maxlength="50" id="Address_Field"></p>

    <p>Phone:

    <input type="text" size="20" maxlength="50" id="Phone_Field">

    <br>

    <p><input name="Pizza1" type="hidden" id="Pizza1"></p>

    <p><input name="Pizza2" type="hidden" id="Pizza2"></p>

    <p><input name="Pizza3" type="hidden" id="Pizza3"></p>

    </p>

    <p><strong>Size:</strong></p>

    <p>

    <input type="radio" name="size" value="small" id="Size_Small">

    small

    <input type="radio" name="size" value"=medium" id="Size_Medium">

    medium

    <input type="radio" name="size" value="large" id="Size_Large">

    large </p>

    <p><strong>Toppings:</strong>:<br>

    &nbsp;&nbsp;&nbsp;&nbsp;

    <input type="checkbox" name="toppings" id="pepperoni">

    pepperoni

    <input name="toppings" type="checkbox" id="suasage">

    sausage

    <input name="toppings" type="checkbox" id="greenpeppers">

    green peppers

    <input name="toppings" type="checkbox" id="onions">

    onions </p>

    <p>

    &nbsp;&nbsp;&nbsp;&nbsp; <input name="toppings" type="checkbox" id="mushrooms">

    mushrooms

    <input name="toppings" type="checkbox" id="olives">

    olives

    <input name="toppings" type="checkbox" id="octapus">

    octapus

    <input name="toppings" type="checkbox" id="seaweed">

    seaweed <strong>&nbsp;</strong></p>

    <p><strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;or Chooose Speciality Pizza

    <select name="Specialty">

    <option>None</option>

    <option>Pepper Steak</option>

    <option>Barbecue Pizza</option>

    </select>

    </strong></p>

    <p><strong>Crust:</strong><strong> </strong></p>

    <p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;

    <select name="crust">

    <option selected>Original</option>

    <option>Large</option>

    <option>XLarge</option>

    </select>

    </p>

    <input name="Pizza1" type="hidden" id="Pizza1" >

    <input name="Pizza2" type="hidden" id="Pizza2">

    <input name="Pizza3" type="hidden" id="Pizza3">

    <p><strong> Special Instructions:</strong><br>

    &nbsp;

    <textarea ref="message"></textarea>

    </p>

    <p>

    <input name="order" type="submit" value="Order Pizza" onClick="checkMandatory();">

    <input name="clear" type="button" value="Clear_Form" onClick="Reset();">

    <input name="save" type="button" value="Save Pizza Details" onClick="DisplayForm();">

    </p>

    </form>

    </p>

    </body>

    </html>





    Please help me if you becuase it is something urgent I need to complete as soon as possible. The help will be appreciated. Thank you
    Copy linkTweet thisAlerts:
    @CharlesAug 18.2006 — 1) We don't do homework, though we're happy to walk you through the process and to steer you in the right direction.

    2) I simply cannot read your post.

    3) You need to start with a valid HTML page. See http://validator.w3.org/ .
    Copy linkTweet thisAlerts:
    @hevansauthorAug 18.2006 — Alright, but the problem that I am having is saving the Phone, Name , and Address Fields when the user clicks the Clear_Form button. But I need the the three hidden fields which is Pizza 1, Pizza2, and Pizza3 to be unchanged if they have values.

    I apologize for the inconvenience of not starting witha direct HTML document, but I'll start over anyway.

    !DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

    <html>

    <head>

    <script language="JavaScript">

    var Pizza1="",Pizza="",Pizza3="";

    var Name="",Phone="",Address="";

    function checkMandatory()

    {

    //mandatory fields

    var Name=document.getElementById("Name_Field").value;

    var Address=document.getElementById("Address_Field").value;

    var Phone=document.getElementById("Phone_Field").value;


    if(Name.length==0)

    {

    alert("Please enter your name");

    }

    if (Address.length==0)

    {

    alert("Please enter your address");

    }

    if(Phone.length==0&&Phone.length!=7)

    {

    alert("Please enter your phone number correctly");

    }

    }

    function SavePizzaDetails()

    {

    var Toppings=false;

    var Specialty=false;

    var holdPizza='size=';

    for(i=0; i < document.forms[0].toppings.length;i++)

    {

    if(document.forms[0].toppings[i].checked==true)

    {

    Toppings=true;

    holdPizza+= '' + document.forms[0].toppings[i].value;





    }//end of if

    if(Toppings)

    {

    holdPizza+='';

    //start loop with 1 so none is skipped



    for(i=0;i <document.forms[0].Specialty.options.length;i++)

    {



    if(document.forms[0].Specialty.options[i].selected)

    {

    Specialty=true;

    holdPizza+='' + document.forms[0].Specialty.options[i].text;

    }//end of if statement

    }//end of for loop



    }// end of second if



    //start loop with 1 so that None is skipped.

    for(i=1;i<document.forms[0].Specialty.options.length;i++)

    {

    if(document.forms[0].Specialty.options[i].selected)

    {

    // variables

    Specialty=true;

    holdPizza+=''+ document.forms[0].Specialty.options[i].text;



    }// end of if



    }//end of second for loop



    }//end of 3rd for loop

    if(Specialty)

    {

    holdPizza+='';

    //either toppings should be choosen OR a specialty pizza selected, not both;



    if(Specialty&&Toppings)

    {

    holdPizza='';//erase stored Pizza Details

    Validation=true;

    alert("Sorry, you are only able to choose toppings OR Specialty for Pizzann"+ "Please Try again");

    }// end of Specialty && Toppings if



    }//end of Specialty if statement



    }// end of Save Pizza Details Function





    //function reset

    function Reset()

    {

    document.forms[0].reset();



    window.document.getElementById("Name_Field").value=Name;

    window.document.getElememntById("Phone_Field").value=Phone;

    window.document.getElementById("Address_Field").value=Address;





    }









    function DisplayForm()

    {

    alert("Pizza1=" + document.forms[0].Pizza1.value + "/n");

    {

    alert("Click save Pizza Details before ordering Pizza!");

    //return false;}

    //else

    //return true;

    }





    }

    </script>
    ×

    Success!

    Help @hevans spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 5.18,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @AriseFacilitySolutions09,
    tipped: article
    amount: 1000 SATS,

    tipper: @Yussuf4331,
    tipped: article
    amount: 1000 SATS,

    tipper: @darkwebsites540,
    tipped: article
    amount: 10 SATS,
    )...