Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

Coding Forum


You are currently viewing our Coding Forum as a guest. Please register to participate.
Login



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

Posts: 61
Trades: 0
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
 
 
Register now for full access!
Old 12-26-2004, 09:16 PM
vivekar's Avatar
Webmaster Talker

Posts: 612
Trades: 0
Use
elseif()

Code:
if()
{
  //do something
}
elseif()
{
   //do thing 2
}
.   // you can extend elseif many times
.
.
else
{
   //do last thing
}
__________________

Please login or register to view this content. Registration is FREE
(Active since 2003) |
Please login or register to view this content. Registration is FREE
vivekar is offline
Reply With Quote
View Public Profile Visit vivekar's homepage!
 
Old 12-27-2004, 01:14 PM
Skilled Talker

Posts: 61
Trades: 0
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: 61
Trades: 0
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: 612
Trades: 0
Good to see that you made it work.
__________________

Please login or register to view this content. Registration is FREE
(Active since 2003) |
Please login or register to view this content. Registration is FREE
vivekar is offline
Reply With Quote
View Public Profile Visit vivekar's homepage!
 
Reply     « Reply to JS verify multiple inputs filled
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 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.23696 seconds with 12 queries