473,388 Members | 1,417 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

Form Validation with alert box

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
4 3260

"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
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

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

Gregc. wrote:
I ended up working it out.

Greg

Aug 28 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Andrew Williams | last post by:
Does anyone know of a way to quickly validate an HTML web form? I need to make sure that certain fields on my form actually contain data and are not submitted blank. I have tried using...
6
by: Charles Banas | last post by:
weird subject - i hope more than just one curious regular will hear me out. :) ok, i've got a bit of a big problem, and i need answers as soon as possible. i know this forum is meant for web...
7
by: AnnMarie | last post by:
My JavaScript Form Validation doesn't work at all in Netscape, but it works fine in IE. I made some of the suggested changes which enabled it to work in IE. I couldn't make all the changes...
4
by: Semi Head | last post by:
Hello folks, I'm looking for a script to validate a specific number value in a standard form input field. An example would be, if someone enters a number into a form input, I want the script to...
11
by: greg.scharlemann | last post by:
I've been playing with this form validation method for a while and have tried an array of things but haven't had any luck with a couple items. 1. The validateForm() function doesn't detect when...
9
by: julie.siebel | last post by:
Hello all! As embarrassing as it is to admit this, I've been designing db driven websites using javascript and vbscript for about 6-7 years now, and I am *horrible* at form validation. To be...
2
by: this one | last post by:
I have the following code <html> <head> <title>Untitled Document</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <script language="JavaScript"...
5
by: kevinmajor1 | last post by:
Hello, all. I'm currently trying to write a script that will perform form validation upon submission. I know that more validation should be performed on the server's side...this is just a test to...
8
by: M.L. | last post by:
Hello. I created a form using JS validation with the form tag as follows: <form name="form1" action="dynaform.php" method="post" onsubmit="return pvg_sub();"> The js validation script sends...
3
uranuskid
by: uranuskid | last post by:
Hey folks, I was going to include a contact form on my website. Well, in the first place that seemed an easy thing to do with a form that prompts a PHP file validating the input vaiables and using...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.