Forum Moderators: open
<html>
<SCRIPT LANGUAGE="JavaScript">
function Disab() {
frm=document.forms['Form1']
if(frm.cbox.checked)
{frm.Submit1.disabled=false}
else {frm.Submit1.disabled=true}
}
</SCRIPT>
<form name="Form1">
<input type="checkbox" name="cbox" id="cbox" onClick="Disab();" checked>
<input type="submit" value="Submit" name="Submit1">
</form>
</html>
Hope that's of some help
Thanks almost there, I want to make a submit button grey out after one click to avoid duplicate submits.
The code below does the job but also hangs the rest of the browser.
What am I doing wrong?
<form name="Form1">
<input type="submit" onmouseup="Form1.Submit1.disabled=true" value="Submit" name="Submit1">
</form>
Kind regards
Walker
<script type="text/javascript">
<!--
var subd = false;
function disable() {
if (subd == true) {
document.getElementById("sub").disabled = true;
}
}
function do_disable() {
subd = true;
disable();
}
function alertSubState() {
alert(subd);
}
//-->
</script>
...
<div>
<form onsubmit="do_disable(); alertSubState();">
<input id="sub" type="submit" />
<input type="button" value="Check" onclick="alertSubState();" />
</form>
</div>
...while the first alert is open showing "true", you can see that the button is disabled in the background, but then after the page reloads, it is back to being enabled.
I think you need to set a cookie onsubmit and then read the cookie onload to determine whether the button should be enabled or disabled.
The only other way I can think of would be to use a GET method on your form, and check onload if (window.location.search.length > 1)...like...
<script type="text/javascript">
<!--
function disableSubmit() {
if (window.location.search.length > 1) {
document.getElementById("sub").disabled = true;
}
}
window.onload = disableSubmit;
//-->
</script>
...
<div>
<form method="GET">
<input name="foo" type="text" value="blah" />
<input id="sub" type="submit" />
</form>
</div>
Jordan
I've found this [javascript.internet.com] one to be of use in the past and whilst it won't grey the button out, it prevents multiple submissions and does basic validation too.
Hope they're of use.
R.