...

View Full Version : Text Field Depending on Radio Options.



victor.gatto
09-28-2011, 07:48 AM
this is php with javascript running<br /><br />


<script type="text/javascript">
function makeChoice()
{
var val = 0;
for( i = 0; i < document.form1.accno.length; i++ )
{
if( document.form1.accno[i].checked == true )
{
val = document.form1.accno[i].value;
if(val=='cedu')
{
document.form1.otherChoice.disabled=false;
document.form1.otherChoice.focus();
}
else
{
document.form1.otherChoice.disabled=true;
}
}
}
}
</script>


<body onload="document.form1.otherChoice.disabled=true">
<form name="form1" action="#" method="post">
<tr>

<td>
<input type="radio" name="accno" value="1" onclick="makeChoice();" />
Yes<input type="radio" name="accno" value="cedu" onclick="makeChoice();"/>
No</td>
</tr>
<tr
<td><br />Global Account Number:</td>
<td><input type="text" name="otherChoice" />
</td>
</tr>
</form>

hyperionXS
09-28-2011, 07:35 PM
And your question is?
Anyway, here is an optimised version of your code

<script type="text/javascript">
function makeChoice(select)
{
if(select)
{
document.form1.otherChoice.disabled=true;
}
else
{
document.form1.otherChoice.disabled=false;
document.form1.otherChoice.focus();
}
}
</script>

<body onload="makeChoice(0)">
<form name="form1" action="#" method="post">
<tr>
<td>
<input type="radio" name="accno" value="1" onclick="makeChoice(1)" /> Yes
<input type="radio" checked="checked" name="accno" value="cedu" onclick="makeChoice(0)"/> No
</td>
</tr>
<tr>
<td>
<br />Global Account Number:
</td>
<td>
<input type="text" name="otherChoice" />
</td>
</tr>
</form>

Alex Vincent
09-29-2011, 04:39 AM
Actually, hyperionXS, this forum is for people to post working snippets of code, not code they need help with specifically.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum