Reply
JS verify multiple inputs filled
Old 12-26-2004, 08:10 PM JS verify multiple inputs filled
Skilled Talker

Posts: 51
I want to use javscript to verify that certain form fields have been filled in instead of php that's currently being used to speed things up a little and lighten the load on the server. I can check one input, but I don't know how to do multiple ones.

Here's what I have (with "onSubmit="return verify()"" in the form tag):

Code:
<SCRIPT LANGUAGE=JAVASCRIPT>
	function verify(){
		if(document.forms[0].name_first.value==""){
			alert("Enter a first name");
			return false;
			}else{
			return true;
			}
</script>
How can I make this function verify more inputs? Thanks.
gregory is offline
Reply With Quote
View Public Profile
 
When You Register, These Ads Go Away!
Old 12-26-2004, 09:16 PM
vivekar's Avatar
Webmaster Talker

Posts: 539
Use
elseif()

Code:
if()
{
  //do something
}
elseif()
{
   //do thing 2
}
.   // you can extend elseif many times
.
.
else
{
   //do last thing
}
__________________
| Submit URL at All the Websites Directory
| Get Certified in Web Design
vivekar is offline
Reply With Quote
View Public Profile Visit vivekar's homepage!
 
Old 12-27-2004, 01:14 PM
Skilled Talker

Posts: 51
Hm. I tried that, but I must have had some error in the code. I'll try again.

Thanks.
gregory is offline
Reply With Quote
View Public Profile
 
Old 12-27-2004, 01:33 PM
Skilled Talker

Posts: 51
OK, I got it. I just had the else if in the wrong place because I wasn't paying attention. For any JS knuckleheads like me, here's how it works:

Code:
<SCRIPT LANGUAGE=JAVASCRIPT>
	function verify(){
		if(document.forms[0].name_first.value==""){
			alert("Enter a first name");
			return false;
			}
		else if(document.forms[0].name_last.value==""){
			alert("Enter a last name");
			return false;
			}
			else{
			return true;
			}
	  }
	</SCRIPT>
Thanks for the help.
gregory is offline
Reply With Quote
View Public Profile
 
Old 12-27-2004, 09:44 PM
vivekar's Avatar
Webmaster Talker

Posts: 539
Good to see that you made it work.
__________________
| Submit URL at All the Websites Directory
| Get Certified in Web Design
vivekar is offline
Reply With Quote
View Public Profile Visit vivekar's homepage!
 
Reply     « Reply to JS verify multiple inputs filled
 

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

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




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.14246 seconds with 12 queries