J
James
Hi,
I am trying to write a function that'll disable all buttons in an HTML
doccument once one is clicked and then proceed with the default action of
that button (which maybe a 'submit' type or maybe a 'button' type with code
for onClick).
Here's what i have so far:
// JavaScript include Document
window.onload = function() {
oneClick();
}
// Disable all buttons
function disableButtons() {
var buttons = document.getElementsByTagName("input");
for (var i=0; i < buttons.length; i++) {
if (buttons.getAttribute("type") == "button" ||
buttons.getAttribute("type") == "submit") {
buttons.disabled = true;
}
}
}
// Attach disable all buttons function to all buttons
function oneClick() {
var buttons = document.getElementsByTagName("input");
for (var i=0; i < buttons.length; i++) {
if (buttons.getAttribute("type") == "button" ||
buttons.getAttribute("type") == "submit") {
var oldOnclick = buttons.getAttribute("onClick");
buttons.onclick = function() {
disableButtons();
oldOnclick;
return true;
}
}
}
}
Whilst all the buttons do get disabled in both IE7 and FF2 once one of them
is clicked, neither of the browsers will continue with a 'button' type
button's original onClick event handler's code. Also, a 'submit' type button
doesn't go on to submit the form in IE7 (which seems to work nicely in FF2).
Any help with this would very much appriciated.
Many Thanks
James
I am trying to write a function that'll disable all buttons in an HTML
doccument once one is clicked and then proceed with the default action of
that button (which maybe a 'submit' type or maybe a 'button' type with code
for onClick).
Here's what i have so far:
// JavaScript include Document
window.onload = function() {
oneClick();
}
// Disable all buttons
function disableButtons() {
var buttons = document.getElementsByTagName("input");
for (var i=0; i < buttons.length; i++) {
if (buttons.getAttribute("type") == "button" ||
buttons.getAttribute("type") == "submit") {
buttons.disabled = true;
}
}
}
// Attach disable all buttons function to all buttons
function oneClick() {
var buttons = document.getElementsByTagName("input");
for (var i=0; i < buttons.length; i++) {
if (buttons.getAttribute("type") == "button" ||
buttons.getAttribute("type") == "submit") {
var oldOnclick = buttons.getAttribute("onClick");
buttons.onclick = function() {
disableButtons();
oldOnclick;
return true;
}
}
}
}
Whilst all the buttons do get disabled in both IE7 and FF2 once one of them
is clicked, neither of the browsers will continue with a 'button' type
button's original onClick event handler's code. Also, a 'submit' type button
doesn't go on to submit the form in IE7 (which seems to work nicely in FF2).
Any help with this would very much appriciated.
Many Thanks
James