Form Validation with alert box

G

Gregc.

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
 
T

Tim Williams

Gregc. said:
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
 
R

RobG

Gregc. said:
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.
 
G

Gregc.

Tim said:

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>
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top