Forum Moderators: open

Message Too Old, No Replies

Enabling/Disabing a submit button

depending on a [un]selected radio input

         

implemens

11:35 am on May 8, 2004 (gmt 0)



Hi,
In my form, I would like to have my submit buttons to be clickeable just if one of my radio buttons was selected. How can I do that?

here's a simple form I'm using (I use PHP).

<HTML>
<HEAD>
<TITLE>My Form</TITLE>
</HEAD>

<BODY >
<H1 ALIGN="CENTER"> Here's my form</H1>

<?
echo "<form method=\"post\" action=\"aver.php\">".
"<table>";
for ($i=0; $i < 2; $i++)
{
echo "<tr>".
"<td>Option".$i."</td>".
"<td><input type=\"radio\" name=\"layout\" value=\"".$i."\"></td>".
"</tr>";
}

echo "</table>";
echo "<BR><input type=\"submit\" name=\"choice\" value=\"Accept\">&nbsp;";
echo "<input type=\"submit\" name=\"choice\" value=\"Help\">";
echo "</form>";

?>
<BR>Bye...
</BODY>
</HTML>

mep00

9:25 am on May 9, 2004 (gmt 0)

10+ Year Member



There's no need to include the php code; it only makes your example harder to read (and less likely to be answered).


<form name="f1" onsubmit="(f1.r1.value=='2')?true:false">
no<input type="radio" name="r1" value="1"><br>
yes<input type="radio" name="r1" value="2"><br>
no<input type="radio" name="r1" value="3">
<input type="submit">
</form>

While the submit will still be clickable, by returning false to the

onsubmit
the form won't be submitted. This is the basic structure. In many cases a function would be called by the
onsubmit
.