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

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 ?
Posted
Updated 29-Mar-14 21:12pm
v2
Comments
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
 
Share this answer
 
what i did is i create two function on JavaScript side and remove required attribute on each client click event of respective buttons.


i.e

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


function onnewsletterbuttonclick ()
{
document.GetElementById('txtreg').required = false;
document.GetElementById('txtnewsletter').required = true;
}
 
Share this answer
 

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