PDA

View Full Version : Disabling a form button for demo...



Errica
Sep 17th, 2007, 03:50 AM
This works but is there a way the button can revert back after it's clicked? Currently, the "Disabled for Demo" sticks.



<html>
<head>
<title>Untitled</title>
<style type="text/css">
<!--
input {
background-color: #FFFFFF;
border: 1px solid #a2a2a2;
color: #a43151;
font-family: Tahoma;
padding: 2px 8px 2px 8px;
}
.disabledDemo {
background-color: #ffe69b;
border: 1px solid #f5a642;
color: #5a5a5a;
}
-->
</style>
<script type="text/javascript">
<!--
window.onload=function() {
document.forms[0].demo.onclick=function(){
DisableButton(this);
}
}
function DisableButton(b) {
b.disabled=true;
b.value=' Disabled for Demo ';
b.className='disabledDemo'
}
-->
</script>
</head>

<body>

<form>

<input class="send" type="Reset" name="demo" value="Add Addresses">

</form>

</body>
</html>

Eli.
Sep 17th, 2007, 07:17 AM
Hey Errica,
If what you are trying to accomplish is stopping the form from submitting, you should rather use "return false;" on the button click, this will send a "false" result on the click action, and will not execute the submit action.

furthermore, you should create some kind of a function that will handle the entire form submitting, with the onsubmit attribute, this way, even if your user submits the form with the "Enter" button on the keyboard, the function will still fire, and will validate your form.
a bit more info here: http://www.w3schools.com/js/js_form_validation.asp

Good Luck,
Eli