I’m binding a click event to a hyperlink. Onclick the value (innertext) of the hyperlink is saved in a hidden field. With this value I’m working after page reload (ASP.NET).
It works – but the problem is:
If I click on link1, everything is okay.
If I click on link2, everything is okay.
If I click on link1 and then (very fast) on link2, the hidden field has the old value (of link1).
Does anyone have an idea to solve this?
$(function () {
var innertxt = "";
$("span[id$='myLink']").bind("click", function () {
innertxt = ($(this).text());
if (innertxt == "myLinkText1" || innertxt == "myLinkText2") {
$("input[id$='myHiddenField']").val(innertxt);
} else { $("input[id$='myHiddenField']").val(""); }
});
});
(Code in comination with ASP.NET page reload, meaning that after clicking a link $(“span[id$=’myLink’]”), the page reloads.)
// edit
I already had an onclick (inline) event.
Apparently the binding was starting after the onclick event has been triggered and so it was too late.
I’ve put the code in the onclick inline event and it’s working.
Thanks for your suggestions!
// end edit
I’ve already had an onclick (inline) event. Apparently the binding was starting after the onclick event has been triggered and so it was too late.
I’ve put the code in the onclick inline event and it’s working.
Thanks for your suggestions!