1

I have a button and som javascript as follows

$("btnCreate").click(function () { $("loadingdiv").show("slow"); $(this).attr("disabled", true); }); $("loadingdiv").hide("fast"); 

It works greate the button is not anymore clickable and grayed out. but the loading div is there and not disapear. page_load not being fired anymore.

7
  • there is no page load in your code Commented Oct 3, 2012 at 7:37
  • You are missing # to identify the id for your button and loadingdiv Commented Oct 3, 2012 at 7:38
  • why are you showing loading div.Are you making a ajax call? Commented Oct 3, 2012 at 7:54
  • Actually I had used # in my code but forgot to write it here. my code is javascript and page_load is in the code behinde file (c#) file. When I remove this line of code from the javascript code it works greate $(this).attr("disabled", true); so it seeams when you make a button to be disabled the event handler for the button will not be triggered. Commented Oct 3, 2012 at 7:56
  • Can you post the rendered HTML your button sits in? For example the form. You can remove any HTML not relevant to this but I think the form tag the button sits in is imprtant. Also, what browser are you using? Commented Oct 3, 2012 at 8:14

2 Answers 2

2

I'm not sure how your code worked to begin with. You are not selecting any element by it's identifier or by a class name.

To select an element by it's identifier you need to add the # before the element id.
To select elements by their class you need to add the . before the the class name.

The below would select the elements by their identifier, assuming that is what they are.

$("#btnCreate").click(function () { $("#loadingdiv").show("slow"); $(this).attr("disabled", true); }); $("#loadingdiv").hide("fast"); 

DEMO - The above code assuming they are your ids

Regarding any page not being submitted or page not being reloaded that should not be impacted by the button being disabled.
Make sure your button is within the form is of type submitand that there is no script attached to the submit event preventing it or similar.

Sign up to request clarification or add additional context in comments.

1 Comment

Hi and thanks. I have used # to get elements by id. and the button is <asp:Button id="btnCreate" OnClick="btnCreate_Click" ... /> and as I showed my code. when I remove this line $(this).attr("disabled", true); it works loadingdiv appears and then disappears again. but when I add that line of code the loadingDiv appears for ever.
0

A little bit of addition I would like to do.

To make that loading div disappear you can bind a callback which executes after whatever data you're loading is loaded, and in that callback you can hide that div.

Well, this answer is too abstract, but thats what I can say from what I see here :)

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.