Click here to Skip to main content
15,881,516 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i have a form with a <input type="submit"> in it
now i want to do some client side validation before the form is posted to its action url. how do i do this. thanks in advance
also i want to remove the automatically inserted fields __VIEWSTATE, __EVENTVALIDATION, as they dont serve me any purpose
so how do i do this
Posted
Updated 31-May-11 19:03pm
v2
Comments
_Damian S_ 1-Jun-11 1:01am    
What kind of validation are you wanting to do? Why not use a validator to do it for you?
tihcra 1-Jun-11 1:04am    
i want to count the number of checkboxes ticked. if they are less than a particular number post the form else display an alert
Sergey Alexandrovich Kryukov 1-Jun-11 1:05am    
Not clear what validation.
--SA
tihcra 1-Jun-11 1:08am    
i want to count the number of checkboxes ticked. if they are less than a particular number post the form else display an alert

you need to onsubmit on form tag. Look at below

<form action="http://www.devinrolsen.com/" method="post" onsubmit="return validate();" name="simpleForm">

In javascript, you need to write the function validate() which will return true if the form values are OK otherwise return false
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 1-Jun-11 1:09am    
Sure, correct, my 5, but look at the alternative I suggest in my solution.
--SA
Why not server-side validation? There are many benefits. It can be more flexible and easier to develop as this is .NET and C#. Javascrips usually takes more development time be the order of magnitude. With ASP.NET you can easily re-generate the same page with validation results and present it back to the user.

—SA
 
Share this answer
 
Comments
tihcra 1-Jun-11 1:11am    
i have read abt validation controls, i think u are talking abt that, but can i validate something so trivial as number of checkoxes ticked with it? can u give some example

(say) all my checkboxes have name attribute set to 'cbData'
tihcra 1-Jun-11 1:14am    
also i am populating by checkboxes at runtime on server side. so how do i add validation control. plus my checkboxes are inside a div tag(with runat attribute set) and not inside form tag
Sergey Alexandrovich Kryukov 1-Jun-11 19:38pm    
Put them all in form and submit POST, on server side check them all and count those checked.
--SA

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