Validating a checkbox in javascript

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.Here in the check Fluency() function , picked the checkbox and then if it is not checked an alert is shown saying “you need to be fluent in English to apply for the job” 22934 We could have done the same thing using j Query and in fact that is what we are going to be doing next .j Query is the most famous JS library ever created , and a lot of people use it daily as it makes their job a lot easier .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 may notice that the only thing I changed from the previous example is that I have deleted the onclick event in the checkbox which makes sense , since in jquery we will be attaching the event to the element no need to call it from the HTML code.

These functions simply change the display type of the div (with id ‘conditional_part’) .

We obtain a reference to the group of radio buttons using the name of the group, and then iterate over all the radio button objects to test which one of them is checked.

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 .

Search for validating a checkbox in javascript:

validating a checkbox in javascript-14validating a checkbox in javascript-32validating a checkbox in javascript-63

Leave a Reply

Your email address will not be published. Required fields are marked *

One thought on “validating a checkbox in javascript”