I was working in a simple interactive form where when a text field get a certain value , the checkbox next to it will be checked, text box will be disabled, also, upon clicking the chekbox will cause the same operation. i first completed the checkbox click operation first. now i had 2 ways-
* make the operations in a separate function & then call it upon text box get the certain value & also check the checkbox manually by code.
* simply generate a click event on the checkbox.
* while trying the second way, i fall in a problem. when we actually click a check box, its first render the checking/unchecking operation & then execute the click event handler. but in case of the manual genration of event, casing reverse, first executing the click handler & then checking uncheking it. then , specially for my problem, as it will be checked for sure(as text box is enabled), i used the following solution:
$(check box-selector).attr('checked','checked').click().attr('checked','checked'). and i got my expected result.
Obviously, for other input elements, this problem shouldn't be occured as for no other elements we will have to checked a input element's status. Such as for a button to be clicked, we can simply use
$("#buttonId").click() and this will work perfectly and will be caught by right handler on time and no ambiguous situation will occur.
Subscribe to:
Post Comments (Atom)










0 comments:
Post a Comment