/    Sign up×
Community /Pin to ProfileBookmark

form field validation

hello.!!how may i use it in the simplest way ..?? if i want to make a form say for making a applicaton form..and in courses apply for say is the header in which i can allow 2 choices can b filled and automatically a message gets flashed when any1 tries to submit a third option..??

to post a comment
JavaScript

8 Comments(s)

Copy linkTweet thisAlerts:
@FangJul 04.2008 — Show the code you are using.
Copy linkTweet thisAlerts:
@aman_batraauthorJul 04.2008 — it doesnt works..

please find the error..

any effort made by you will be appreciated..

thanx..,

<html>

<head>

<script type="text/javascript">

function validate_required(field,alerttxt)

{

with (field)

{

if (value==null||value=="")

{alert(alerttxt);return false;}

else {return true}

}

}function validate_form(thisform)

{

with (thisform)

{

if (validate_required(firstname,"Firstname must be filled out!")==false)

{email.focus();return false;}

}

with (thisform)

{

if (validate_required(lastname,"lastname must be filled out!")==false)

{email.focus();return false;}

}

with (thisform)

{

if (validate_required(email,"Email must be filled out!")==false)

{email.focus();return false;}

}

with (thisform)

{

if (validate_required(email,"Email must be filled out!")==false)

{email.focus();return false;}

}

}

</script>

</head>

<body>

<form action="submitpage.htm"

onsubmit="return validate_form(this)"

method="post">

FIRSTNAME:<input type="text name="firstname"size="40"><br>

<br>

<br>

LASTNAME: <input type="text name="lastname"size="40"><br>

<br>

<br>

GENDER:<br>

MALE: <input type="radio" name="sex" value="male"><br>

FEMALE:<input type="radio" name="sex" value="female"><br>

<br>

<br>

*COURSE APPLYING FOR:<br>

B-tech:

<input type="radio" name="course applying for" value="B-tech">

<br>

M-tech:

<input type="radio" name="course applying for" value="M-tech">

<br>

<br>

<br>

Email: <input type="text" name="email" size="30">

<input type="submit" value="Submit">

</form>

</body>

</html>
Copy linkTweet thisAlerts:
@FangJul 05.2008 — Which third option?
Copy linkTweet thisAlerts:
@aman_batraauthorJul 05.2008 — i dint get u sir..,
Copy linkTweet thisAlerts:
@FangJul 06.2008 — ... which i can allow 2 choices can b filled and automatically a message gets flashed when any1 tries to submit [B]a third option[/B]..??[/QUOTE]This is what you require.
Copy linkTweet thisAlerts:
@aman_batraauthorJul 06.2008 — exactly..

say anyone selects two options but if he tries for third some alert box comes or watever like that...

i hope i was clear??
Copy linkTweet thisAlerts:
@FangJul 06.2008 — What 3rd option?B-tech:
&lt;input type="radio" name="course applying for" value="B-tech"&gt;
&lt;br&gt;
M-tech:
&lt;input type="radio" name="course applying for" value="M-tech"&gt;
Copy linkTweet thisAlerts:
@aman_batraauthorJul 23.2008 — third option is say under BTECH he has to fill choice of trade like CSE ECE TEXT CHE CIVIL EEE then i want him to opt for at the max 2 options out of these then wat will b the code?? and i want that if user tries to fill the third option then an alert box gets flashed saying that u cannot post more than two
×

Success!

Help @aman_batra spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...