Validating drop down lists select list validation using javascript

Posted by / 22-Aug-2017 17:54

To set the value attribute, we can simply use the set Attribute method of the option element object.

Finally, we append this newly created option element to the list as a child element itself. If we know the index of the option in the list, we can simply use the remove method of the list object to remove the option.

First, download the Java Script form validation script here.

The zip file contains the javascript file, examples.

For example, you can have an input field that should not be empty, should be less than 25 chars and should be alpha-numeric. In some dynamically programmed pages, it may be required to change the validations in the form at run time.

In other words, in order to validate a field, you just associate a set of validation descriptors for each input field in the form. For such cases, a function is included which clears all validations in the validator object. Note that this validation if for fields like Textbox and multi-line text box.

For ‘selections’ like drop down and radio group, use an appropriate validation like ‘dontselect’ or ‘selone_radio’.

The idea is to create a set of “validation descriptors” associated with each element in a form.By default the caption for that list is the first item.For example if you’re asking a user to select a country the first option is “Select a country” and the name of the countries follow so we need to check if the first option is selected and then display a message to select an option.I have two dropdown lists to select value from 0 to 23.What I want is that when the user selects a value from the first list, he cannot select a value lower than this value in the second list.

validating drop down lists select list validation using javascript-50validating drop down lists select list validation using javascript-39validating drop down lists select list validation using javascript-71

In order to implement this, we need to write a couple of Javascript functions: In Java Script we can create elements dynamically using the create Element method of the document object.

One thought on “validating drop down lists select list validation using javascript”