Validating a checkbox in javascript Talk to sluts free chat rooms


06-Jun-2020 06:24

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 .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.

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.22934 I am sure most of you have seen a lot on the Internet which is when there is something hidden in the form , something like a section for extra information or feedback and you press on a checkbox to toggle it and show it or hide it . We are going to be using j Query because it will be much easier and shorter and I do not want you to get lost in a lot of lines but this example can be done with only javascript and it will not be hard .In the code above we have a div and inside it we have a form that contains a text with a placeholder text of name which will contain the name of the applicant , another input with type e-mail , checkbox and a text area .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 .