JQuery - Avoid Modifying Selected Input

Is there a way to prevent users from changing the selected input ?.

I have a form with an option already selected, and I want to know users that they do this, and I tried to do it

I have a choice with id = users,

   $("#users").change(function(){
        confirm("You are going to change the default value. Are you sure?");
   });

One of the problems that I am facing is that this only happens if I click on a parameter, it does not happen as soon as I click on the select input.

Another thing is that it shows 2 times, is there a way to handle this?

And the last question, how can I do this after clicking the "Cancel" button in the confirmation window, it will not display a list of parameters, and if I click "accept", it should display the parameters.

I assume that I am trying to do this intermediate event between the fact that you are not doing anything and after the click event on this select.

Hope someone can help me.

Thanks in advance

Javier Q

+5
source share
2 answers

This is basically what Tetsujin said “No They”, but there is no reason why you cannot do this with a choice. Just grab the muscles instead of clicking (so it's instant) and, if necessary, prevent the default behavior:

http://jsfiddle.net/zKHaj/5/

In addition, you can add a boolean like "hasAccepted", so you only need to confirm once.

+6
source

You can disable selection input (either in tag c disabled="disabled", or at run time)

$("#users").attr("disabled","disabled");

, ( .)

+1

All Articles