Validating a checkbox in javascript One hundred percent free sex chat

Sometimes you might want to submit the form just when the user clicks a checkbox, rather than making the user press the submit button.

validating a checkbox in javascript-39

This is the same exact if statement we used in the first example with only a very small change , which is instead of getting the checkboc using Element By Id() we are using the “this” keyword.

If you are not familiar with the ‘this’ keyword , here in this example it refers to the target that fired that event which is here the checkbox we want to grab.

A check box in a form has only two states (checked or un-checked) and is independent of the state of other check boxes in the form, unlike radio buttons which can be grouped together under a common name.

Let us look at the HTML code showing two check boxes: See the demo The textarea for ‘work permit’ gets disabled if ‘No’ is chosen for ‘Willing to work abroad ?

Inside this anonymous function we are having the same if statement we used in the previous example to check whether the checkbox is checked or not.

And inside them we are using the jquery hide() and show() functions .Then we are attaching to it an on change event and inside it we are using the anonymous function syntax for the second time.The code that is inside the anonymous function will be run each time the event is fired.There are two events that you can attach to the checkbox to be fired once the checkbox value has been changed they are the onclick and the onchange events.There is a problem with the onchange event is that it is not called until the checked state has been updated and since Internet Explorer does not fire the on Change event till the checkbox loses focus so it will create different results than in Google chrome and other browsers so to avoid all this I recommend you stick to the onclick event.You do not need to worry if you do not know j Query , it’s concepts are very easy and I will be explaining everything as we go along.