Click to See Complete Forum and Search --> : Enabling/Disabling submit button?


Cabadam
09-02-2003, 04:20 PM
OK, couldn't find any references really on this so here I am.

I have a form with which I want to add event handlers for the onChange event to three edit fields. Right now I am just working with the first one.


<script language="JavaScript">
function onNameChange()
{
}

function onRoomChange()
{
}

function onEmailChange()
{
}
</script>

<form action="snipped" method="post" name="form1">
<table width="100%" border="0">
<tr>
<td width="11%">Name:</td>
<td width="89%"><input type="text" name="name" onChange="onNameChange"></td>
</tr>
<tr>
<td>Room No:</td>
<td><input name="room" type="text" onChange="onRoomChange"></td>
</tr>
<tr>
<td>Email Address:</td>
<td><input type="text" name="email" onChange="onEmailChange"></td>
</tr>
<tr>
<td><input type="submit" name="submit" value="Submit"></td>
<td>&nbsp;</td>
</tr>
</table>
</form>

What I want to happen is I want to validate text in the text field and if it is invalid, grey out/disable the submit button. Is this possible in javascript?

Thanks

David Harrison
09-02-2003, 04:35 PM
If you want to disable the submit button, you can use this:

document.form1.submit.disabled=true;

And to enable it:

document.form1.submit.disabled=false;

Cabadam
09-02-2003, 05:39 PM
Grr... I must be doing something wrong. It seems like the handler is never getting called - though I'm not getting any errors in IE. Source is basically the same as in the original post. I've tried throwing in a document.writeln("dfsf"); into the handler but nothing ever got displayed.

Any ideas what I'm doing wrong here?

Charles
09-02-2003, 05:42 PM
Your handlers should look more like onchange="onNameChange()".