Form Validation with alert box

Discussion in 'Javascript' started by Gregc., Aug 27, 2006.

  1. Gregc.

    Gregc. Guest

    Hi

    Would someone have a basic example of form validation that validates
    name and address, but using only one alert box that displays which
    fields haven't been completed? I can do it on an individual basis, but
    want to consolidate it to one alert message.

    G
     
    Gregc., Aug 27, 2006
    #1
    1. Advertising

  2. Gregc.

    Tim Williams Guest

    "Gregc." <> wrote in message
    news:...
    > Hi
    >
    > Would someone have a basic example of form validation that validates
    > name and address, but using only one alert box that displays which
    > fields haven't been completed? I can do it on an individual basis, but
    > want to consolidate it to one alert message.
    >
    > G
    >


    Why not show what you have so far?

    Tim
     
    Tim Williams, Aug 28, 2006
    #2
    1. Advertising

  3. Gregc.

    RobG Guest

    Gregc. wrote:
    > Hi
    >
    > Would someone have a basic example of form validation that validates
    > name and address, but using only one alert box that displays which
    > fields haven't been completed? I can do it on an individual basis, but
    > want to consolidate it to one alert message.


    Loop through the controls and check them. Start with an empty error
    message string, then concatenate error messages as you go. When you've
    finished, check the string. If it's empty, you haven't detected any
    errors. Otherwise, display the message.

    A better solution is to have an error message area associated with each
    input that is validated. Validate individual controls onblur (or onkey
    press, onchange, whatever suits) and write error messages to the error
    message area. That way the user can see the messages and correct the
    input while it's still there. When they get it right, the message
    disappears.

    It fits well with server-side validation too - the validated page is
    returned with server-supplied messages in the error message areas.

    There are lots of examples in the archives.


    --
    Rob
     
    RobG, Aug 28, 2006
    #3
  4. Gregc.

    Gregc. Guest

    Tim Williams wrote:
    >> Why not show what you have so far?

    >
    > Tim


    Tim, this is what I have done so far:

    <html>
    <head>
    <script type="text/javascript">
    function updateOrder(obj){
    var type = obj.name;
    var pizza= new Array("Supreme", 12);
    var pizza2 = new Array("Italian",12);
    var w=obj.selectedIndex;
    var selected_text = obj.options[w].text;
    var qty1=document.getElementById("orderQty");
    var piz1=document.getElementById("PizzaType")
    var oSum = document.forms.form1.orderQty;
    var inLisAlready = false;

    for(i=0; i<oSum.length; i++){
    if(oSum.options.value==qty){
    if(obj.value==0){
    oSum.options=null;
    }
    else
    {oSum.options.text=(obj.value);
    }
    inLisAlready=true;
    break;
    }
    }
    if (!inLisAlready){
    if(obj.value!=0){
    oSum.options[oSum.length]= new Option (obj.value);
    }

    }

    }

    </script>
    </head>
    </script>
    </head>
    <body topmargin="0" leftmargin="0" marginwidth="0" marginheight="0"
    style="text-align:center">
    <form name="form1" method="post" action="" onsubmit="">
    <select name="Supreme" id="Supreme" onchange="updateOrder(this);">
    <option>0</option>
    <option>1</option>
    <option>2</option>
    <option>3</option>
    <option>4</option>
    <option>5</option>
    </select>
    <body topmargin="0" leftmargin="0" marginwidth="0" marginheight="0"
    style="text-align:center">
    <form name="form1" method="post" action="" onsubmit="">
    <select name="Italian" id="Italian" onchange="updateOrder(this);">
    <option>0</option>
    <option>1</option>
    <option>2</option>
    <option>3</option>
    <option>4</option>
    <option>5</option>
    </select>
    <td bgcolor="#FFE9BB" class="borderBR"><select name="Type of Pizza"
    size="10" id="PizzaType">

    <option>Pizza Ordered</option>

    </select> </td>


    <td bgcolor="#FFE9BB" class="borderBR"><select name="orderQty" size="4"
    multiple="multiple" id="orderQty">
    </select>

    </body>
    </html>
     
    Gregc., Aug 28, 2006
    #4
  5. Gregc.

    Gregc. Guest

    Gregc. wrote:
    I ended up working it out.

    Greg
     
    Gregc., Aug 28, 2006
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mersh
    Replies:
    0
    Views:
    523
    Mersh
    Mar 13, 2007
  2. Ganesh
    Replies:
    0
    Views:
    585
    Ganesh
    Jun 29, 2007
  3. Bill
    Replies:
    3
    Views:
    150
    Thomas 'PointedEars' Lahn
    Oct 23, 2003
  4. bnp
    Replies:
    4
    Views:
    348
  5. form validation and alert

    , Mar 23, 2005, in forum: Javascript
    Replies:
    3
    Views:
    95
Loading...

Share This Page