By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,384 Members | 1,829 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,384 IT Pros & Developers. It's quick & easy.

Form Validation with alert box

P: n/a
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

Aug 27 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a

"Gregc." <gr*********@bigpond.comwrote in message
news:11**********************@m73g2000cwd.googlegr 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
Aug 27 '06 #2

P: n/a
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

Aug 28 '06 #3

P: n/a

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>

Aug 28 '06 #4

P: n/a

Gregc. wrote:
I ended up working it out.

Greg

Aug 28 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.