1

here is the my code;

Loading data from database my buttons,after loading finished,I want to trigger some client script,.in my senario,after clicked the first button ,want to disable clicked button, and enable the secon button(clickable element) I am able to disabled fisrt button, I couldnt enable secont button though **

First button

 <button type="button"  class="btn  btn-default" 
                              onclick=" 
                              var resetbtnid = '#m-' + $(this).attr('id'); //I am getting 


                              $(this).prop('disabled', true);
                              $('#resetbtnid').removeAttr('disabled');

                              "
                             name='<%# DataBinder.Eval(Container.DataItem,"Fiyat") %>'
                             id='<%# DataBinder.Eval(Container.DataItem,"Id") %>' >
                             <span class="glyphicon glyphicon-ok-sign"></span></button>

Second button

 <button type="button" disabled="disabled"  class="btn btn-default"
    id='m-<%# DataBinder.Eval(Container.DataItem,"Id") %>' 
    name='<%# DataBinder.Eval(Container.DataItem,"Fiyat") %>' >
     <span class="glyphicon glyphicon-minus-sign"></span></button>

3 Answers 3

3

Your selector is incorrect. In your code $('resetbtnid').removeAttr('disabled')

Use # if you want ID selector like $('#resetbtnid').removeAttr('disabled')

You can use .prop() like $('#resetbtnid').prop('disabled', true/false)

Use . for class selector.

EDIT:

As resetbtnid is a variable use it without quotes

 var resetbtnid = '#m-' + $(this).attr('id'); 
 $(resetbtnid).removeAttr('disabled');
Sign up to request clarification or add additional context in comments.

1 Comment

@user2460637, use $(resetbtnid).removeAttr('disabled');
1

Try this:

//Enable

$('#buttonID').attr('disabled', 'disabled');

//Disable

$('#buttonID').removeAttr('disabled');

2 Comments

need eabled not disabled
Sorry the question's title told me that!:)
1

When there are two buttons, one is enabled (default), the second is disabled, it looks like this in code

HTML:

<button id="btn1" />
<button id="btn2" disabled="disabled" />

JS:

$(document).ready(function() {
        $('#btn1').click(function () {
            $('#btn1').prop('disabled', 'disabled');
            $('#btn2').prop('disabled', false);
        })
    })

That should do the job!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.