Onclick Event In Anchor Tag Not Working In Ie10
Solution 1:
The problem is with your server side code, not the browser or JavaScript.
If you check the JavaScript console in IE10 you will see the following error when clicking the link:
SCRIPT5009: 'ValidatorValidate' is undefined
Which points to the second line in the function:
functiondoSearch() {
var regExValidate = document.getElementById("ctl00_BrokerSearchMiddle_ctl00_ValidPostalCode");
ValidatorValidate(regExValidate);
var postalCode = $find("ctl00_BrokerSearchMiddle_ctl00_PostalCode").get_value();
if (regExValidate.isvalid && postalCode.indexOf("e.g") == -1) {
document.location.href = "?postalCode=" + postalCode;
}
}
This means the onclick
is working just fine, you simply have JS error.
Now the question is why ValidatorValidate
exists in other browsers (even IE9) but not in IE10. Well, in IE10 the script where it's being defined is not included, meaning the server never put the line <script src="...">
with that URL as part of the output to the browser.
I can only guess that the server side code is checking the browser version and according to that include certain scripts. Check that code and get rid of such things as it's never a good idea.
After some research I found what's going on. You are using Sitefinity version 3.7 to build your site (according to this question of yours) and as officially stated here:
I want to inform you that unfortunately Sitefinity 3.7 does not support Internet Explorer 10 and your Sitefinity 3.7 might not work properly with this browser version. Apologies for the inconvenience
You will have to upgrade your Sitefinity if you want IE10 support.
Solution 2:
The below code works on every major browser (I just tested it on IE10, IE9, Chrome 26.0.1410.64, and the latest firefox release).
<ahref="#"id="myAnchor"onclick="myFunction();return false;">click me</a><scripttype="text/javascript">functionmyFunction(){
alert("Anchor was clicked");
}
</script>
In other words, your syntax is fine, but the anchor tag simply will not appear without inner text unless you use CSS to force a width and height.
CSS option:
a{
display: block;
width: 100px;
height: 20px;
}
Post a Comment for "Onclick Event In Anchor Tag Not Working In Ie10"