javascript - Using different methods on a button based on its value -


i have series of buttons created database, set active or disabled based on value in database.

i trying create script sees value button has , changes other state.

my buttons

    <input type='button'     name='activebutton'     id='actbutton11'     value='active'     class='activebutton'     /> 

my script looks this, unable differentiated between active , disabled buttons.

i can change buttons value doesn't change value of c if method called again.

i want user able call new appropriate method once button has changed state.

$(document).ready(function(){     $(".activebutton").click(function(){     var c = $(this).val();    //  alert(c)    if(c = "active")             {              var answer = confirm("disable button?")          if (answer)              {                var $inputelement = $(this),                $("activebutton").val("disabled");              }            }    else            {                var answer = confirm("activate button?")                var $inputelement = $(this),                {                    $("activebutton").val("active");                }             }       }); });  

you can this:

$(document).ready(function () {     $(".activebutton").click(function () {         var $inputelement = $(this),             c = $(this).val();          if (c === "active") {             var answer = confirm("disable button?");             if (answer) $inputelement.val("disabled");          } else {             var answer = confirm("activate button?");             if (answer) $inputelement.val("active");         }     }); }); 

fiddle demo


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -