i created jsp page..in it i used check boxes and textboxes..after clicking checkbox it is not validating the text...i need to validate both the fields..here is my code..its urgent for me...i need help where the code is wrong..
Change this line of the code. All your checkboxes and text fields have the same name. What you would want to do is check if a checkbox is checked, and if it is, check if the corresponding text field has a value. You can do it like this
You can implement this similar logic for the other text field too...
Thanks for your reply..i tried it is working...the problem is if i didnt check the check-box it is not showing any alert message that checkbox should be selected...can you help me out regarding that..i need both check box and textfield should be validated...that means if i check checkbox and left text field it should ask for 'Enter the value inText box'..vice-versa..or suggest me where to change the code...
madhuri both your checkboxes and text fields have the same name. So document.getElementsByName('balrdys') will return both of them. Then when you iterate over the elements, you'll get an error when the element is a text box as there is no checked property on text boxes. You can assign an ID to all the checkboxes and check if any of them are checked using getElementById as I already gave you an example...
Joined: Mar 30, 2010
i got your point..if i didnt check the checkbox it is directly loading..that means it is not showing the errors...i had pasted the same example what you had given to me...i need help that if i left any one and press submit..it is should throw an error..i changed the code as follows..
So what you do is you give a separate ID to your checkboxes and text boxes and then check them using getElementById. This is just one way of implementing it, there are other ways of implementing the same thing as well...