IE8 JS problem. Looking for better solution.
philg | Posted 2:25am 24. March 2010 Server Time |
Hi Folks,
I have found a problem which I have got a solution to but I am wondering if any of you know of something better. This problem only seems to occur in IE8, for the users with IE6 it was not a problem. This is on a company Intranet where there are very few users with other browsers so I only really need to worry about IE.
I have a form that contains a lot of JavaScript actions but if one particular text box is selected, I need to prevent all other actions until the onBlur event of that text box has completed or the users can end up accidentally changing the wrong records.
Below is a stripped down version of the code I am using for testing (test.asp) but I can only get it to work properly and ignore the click on the checkbox by using an alert. I would prefer to do this invisibly to the users because there are already so many alerts on the page that I worry that people are not paying attention to them. Adding one that they can ignore just gives them an excuse for not reading the important ones.
<script language="JavaScript">
// Working method to cancel click events.
// alert("I don't want this stupid !*??*! alert box!");
// Failed methods to cancel click events.
// function pause(ms){var dt=new Date();while((new Date())-dt<=(ms*1000)){}}
// event.returnValue=false;
// document.test.scoobie.value='goaway';
function noway(go){
if(document.all){if(event.button==1){alert("I don't want this stupid !*??*! alert box!");return false;}}
if(document.layers){if(go.which==3){return false;}}
}
function stopclicks(){
if(document.layers){document.captureEvents(Event.MOUSEDOWN);}else{document.onmousedown=noway;}
}
</script>
<form name="test" method="post" action="test.asp">
Testing click disable on field entry<br>
You should be able to toggle this tick box on and off. The form will resubmit each time.<br>
<input type="checkbox" name="test" value="y"<%If Request("test")="y" Then Response.Write " checked" End If%> onClick="document.test.submit();"> Go on, click me, I dare ya!
<br>
Now click into this field, and then try toggling the checkbox again, the form should resubmit but the check box should remain in it's previous state.<br>
<input type="text" name="ttxt" value="<%=Request("ttxt")%>" onFocus="stopclicks();" onBlur="document.test.submit();">
<input type="hidden" name="scoobie" value="">
</form>
|