Web Hosting Talk







View Full Version : JAVA enable/disable input="Image" Button


jowd
01-13-2005, 04:01 AM
Hi All,

I think I'm going crazy over this... I've spent many hours now trying to figure it out.

Here's the goal:
I want to force the acknowledgement of a legal statement by
disabling the submit button on a form until the user has checked
a box. When the checkbox has been checked then the submit
button becomes enabled allowing the user to submit the form.

Problem:
When you try to click on the checkbox the following error is generated:
Error: Object doesn’t support this property or method

Here’s the code (not working):
<HTML>
<HEAD>
</HEAD>
<BODY>
<form action="processform.php" method="post" name="cngcc" id="">
<input type="checkbox" name="acknowledgeITADA" value="yes"
onClick="javascript:enableDisable()">Acknowledged.<br>
<input type="image" name="submit" alt="submit" border="0"
src="_art/BoxOrderSearch.gif" disabled="disabled" ><br>
</FORM>


<script language="JavaScript">
<!--
function enableDisable() {
if (document.cngcc.acknowledgeITADA.checked)
{
document.cngcc.submit.disabled = false;
}
else
{
document.cngcc.submit.disabled = true;
}
}
//-->
</script>

</BODY>
</HTML>
Notes Worth Mentioning:
This code works perfectly if the button is set to type=”submit” (but of course then it’s not a graphical button).

Also, if you change the name from “submit” to “search” or something else then it generates a different error:
Error: ‘document.cngcc.search’ is null or not an object

Thanks in advance for any help... you guys are the best!

-- Jonathan

gogocode
01-13-2005, 06:35 PM
if (document.cngcc.acknowledgeITADA.checked)
{
document.cngcc.submit.disabled = false;
}
else
{
document.cngcc.submit.disabled = true;
}


Change the name of your button, "submit" is the name of a method of the form object.

ilyash
01-13-2005, 08:12 PM
what ^ said should work.
And just so you know.. you have zero java there..
you have "javascript"... which is completely different.

azizny
01-13-2005, 09:20 PM
as they said...
And just so you know... javascript can be ignored/disabled easly..
you should use a post/form checker or PHP form validation instead

Peace,

jowd
01-13-2005, 10:13 PM
Originally posted by gogocode
Change the name of your button, "submit" is the name of a method of the form object.
gogocode, tried that. It generates a different error. (See under "Notes Worth Mentioning:" in my original post.)

Actually, I ended up doing what azizny suggested (good point) to solve the problem. But the disable/enable thing would still be cool. :cool: