HighDots Forums  

Fix for IE button bug

JavaScript discussion (multi-lingual) JavaScript discussion (alt.comp.lang.javascript)


Discuss Fix for IE button bug in the JavaScript discussion (multi-lingual) forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Kimmo Laine
 
Posts: n/a

Default Fix for IE button bug - 01-03-2006 , 05:50 AM






I noticed a bug in IE, when using button-elements instead of input submits.
One button works okay, but when you use multiple button-elements on the same
form, they are all submitted, instead of the one that was clicked. So I
wrote a little script to workaround it, I attach an onclick-event to each
button on the page, and once the button is clicked, it loops through all
button-elements on the form disabling them, and finally enabling the one
that was clicked.

I use this as a separate .js file and include it to every page that uses
multiple button-elements.
and I use the following syntax to include it only when the browser is IE:
<!--[if IE]>
<script type="text/javascript" src="buttonfix.js"></script>
<![endif]-->

buttonfix.js:
----
function buttonfix(){
var buttons = document.getElementsByTagName('button');
for (var i=0; i<buttons.length; i++) {
buttons[i].onclick = function () {
for(j=0; j<this.form.elements.length; j++)
if( this.form.elements[j].tagName == 'BUTTON' )
this.form.elements[j].disabled = true;
this.disabled=false;
}
}
}
window.attachEvent("onload", buttonfix);
----

I hope this helps someone who is struggling with the same thing. Also: if
you find something to correct or something that can be improved, please let
me know.

(If you wonder why I wanted to use buttons instead of input-elements, the
answer is that button elements allows html-formatting and images inside the
button, so you can insert images inside the submit buttons that way or
underline certain letter from the button label. That's why.)

Sincerelly,
Kimmo Laine

--
"En ole paha ihminen, mutta omenat ovat elinkeinoni." -Perttu Sirviö
spam (AT) outolempi (DOT) net | Gedoon-S @ IRCnet | rot13(xvzzb (AT) bhgbyrzcv (DOT) arg)



Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.