logo-dw

Go Back   Dreamweaver Club Forums > Hand Coders Forum > Javascript and JS frameworks
Register FAQ Members List Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Display Modes
Old 01-05-2012, 06:41 PM   #1
tony09uk
 
Join Date: Oct 2010
Posts: 340
Default form.indexOf

I am trying to put together a form validation script....its my first attempt at not following a tutorial varbaitim, and it's not going well. I hope someone can give me some advice where i'm going wrong.

I have created four information boxes and a submit button:

<form name="test" onSubmit="return run()"/>
Email:* <input type="text" name="address" /><br/>
name:* <input type="text" name="name" /><br/>
Feedback:* <textarea name="fb" cols="20" rows="5" /></textarea><br/>
home address: <input type="text"name="home" /><br/>
<input type="submit" name="button" value="send" />
</form>

I am trying to get the user to input an Email address into box 1 and some information into boxes two and three and have it checked when they hit the submit button so I created this function:

function run(){
var string = document.test.address.value
if((string.indexOf("@")==-1)||(document.test.name=="")||(document.fb=="")){
alert("fill this out properly!!!")
return false
}else
return true
}

Firstly I realise that this would not be a good script for a real world environment, but im just trying to learn programming.

My problem is that the alert message will pop pop up if an @ is not inputted into the box, but then I don't get anymore messages when the other boxes are left empty....why?
tony09uk is offline   Reply With Quote
Reply


Thread Tools
Display Modes

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

Forum Jump


All times are GMT. The time now is 05:25 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Copyright 2006 DreamweaverClub.com