Zohaib
Zohaib

Reputation: 417

Skip the usual behaviour of select Input using javascript

I have a form having select Input with some options in the drop down option list.

Requirement: On click of the select Input I need to check validation of form.If the form is incomplete I need to skip the behaviour of select input i.e do not show the option list. However if the form is complete the select input should show me the options(i.e normal behaviour).

Problem : I did try event.preventDefault() to skip the further action assuming that the select input will not show me the options if the form was incomplete. But this aint workin

Find the code:

$('selectInput').addEvent('click', function(event){
  if(!validateForm()){
    if(event.preventDefault){
      event.preventDefault();
    } else {
      //IE
      event.returnValue = false;
    }
  }
});

Upvotes: 1

Views: 236

Answers (2)

jadkik94
jadkik94

Reputation: 7078

You could disable/enable the select everytime the validation parameters are changed ?

Otherwise, I noticed you are using jQuery, so you could imple,ent your own or one that is already made with your features...

Upvotes: 2

Jermin Bazazian
Jermin Bazazian

Reputation: 1970

My suggestion would be to add the options in your onclick. If the validation passes, add the option otherwise don't do anything.

Upvotes: 1

Related Questions