Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Form Validation with alert box

Reply
Thread Tools

Form Validation with alert box

 
 
Gregc.
Guest
Posts: n/a
 
      08-27-2006
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

 
Reply With Quote
 
 
 
 
Tim Williams
Guest
Posts: n/a
 
      08-27-2006

"Gregc." <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.com...
> 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


 
Reply With Quote
 
 
 
 
RobG
Guest
Posts: n/a
 
      08-28-2006
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

 
Reply With Quote
 
Gregc.
Guest
Posts: n/a
 
      08-28-2006

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[i].value==qty){
if(obj.value==0){
oSum.options[i]=null;
}
else
{oSum.options[i].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>

 
Reply With Quote
 
Gregc.
Guest
Posts: n/a
 
      08-28-2006

Gregc. wrote:
I ended up working it out.

Greg

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to create a form Alert - Not using Alert Boxes Mersh Java 0 03-13-2007 04:14 PM
form validation and alert elaines@ori.org Javascript 3 03-24-2005 07:09 PM
Form Validation Problem...Persisiting form fields on validation failure. bnp Javascript 4 05-12-2004 12:16 PM
ALERT: Virus Scam Alert! Toronto Garage Door Company Computer Support 1 11-18-2003 04:16 PM
keeping to current page after form validation alert Bill Javascript 3 10-23-2003 12:15 AM



Advertisments