Click here to Skip to main content
15,113,873 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:

on one page i have two different set of inputs that i want to validate using html5 required attribute.

first form is registration form and it should validate control for registration. second form is for newsletter subscribe it should validate email with required attribute. i have two button one for registration and other for news subscription. individual both works good but when i put them on same form and click on register button it also validate newsletter text box by saying please fill out this field.

i want that when i click on news letter submit button then only it should ask for email and when i click on register form it should ask for controls which are added for registration.

can some please help me ?
Updated 29-Mar-14 22:12pm
Sampath Lokuge 30-Mar-14 3:12am
Can you put the code snippet for your forms ?

No idea, if this suggestion will work or not, but try removing the validations once you click the button where its not requried
what i did is i create two function on JavaScript side and remove required attribute on each client click event of respective buttons.


function onregisterbuttonclick ()
document.GetElementById('txtreg').required = true;
document.GetElementById('txtnewsletter').required = false;

function onnewsletterbuttonclick ()
document.GetElementById('txtreg').required = false;
document.GetElementById('txtnewsletter').required = true;

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900