|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Javascript radio button
I am trying to implement a feature on the registration of my site so that users have a Yes/No radio button to check if they have a band and if they select yes, then a text box to enter the band name will show up but I dont know how to print the HTML useing JavaScript so that it will just go undeneath the Yes/No radio buttons and I've had no luck finding this seemingly basic function through Googleing. Heres my code....
Code:
<script language="JavaScript">
<!-- hide
function bandName()
{
SOME HOW PRINT "<INPUT TYPE='TEXT' NAME='reg[bandname]' VALUE='' SIZE=30 MAXLENGTH=150>"!!!!!!
}
// end the hiding comment -->
</script>
then some HTML tables and stuff... Code:
<INPUT TYPE="radio" NAME="reg[haveband]" VALUE="0" checked> no <INPUT TYPE="radio" NAME="reg[haveband]" VALUE="1" onClick="bandName();"> yes<br> If somebody knows a better way to do this w/ PHP that would be great too! Thanks. |
|
#2
|
|||
|
|||
|
RE: Javascript radio button
DorkRawk,
Let me make a two suggestions here. 1. Rather than displaying a textfield when the user hits 'yes' option, you can just provide the textfield to enter bandname without option buttons. Then if you has entered something on the textfield that mean the answer for your question 'Have Band?' is yes. You can let them know by saying 'Leave blank if you have no band'... 2. You could send user to another page to enter the band name if you selected the answer 'yes' in option buttons. I do not accept using JavaScript much in validation though it is faster than other methods because some visitors of yours browser's JS can be disabled. I hope I was clear. |
|
#3
|
|||
|
|||
|
RE: Javascript radio button
Whenever you are hiding or emerging elements, you want to incorporate some kind of <div> tag along with your javascript so it has something to reference as a start and finish. Try this on for size:
Your javascript: Code:
<script type="text/javascript">
function showlayer(el)
{document.getElementById(el).style.visibility = 'visible'}
function hide(el)
{document.getElementById(el).style.visibility = 'hidden' }
</script>
Your html: Code:
<input type=radio name="reg['bandname']" value="no" checked onClick='hide("divName")'>No<br />
<input type="radio" name="reg['bandname']" value="yes" onClick='showlayer("divName")'>Yes<br />
<div style="visibility:hidden" id="divName">
<input name="text" name="reg[bandname]" value="" size="30" maxlength="150">
</div>
Enjoy! |
![]() |
| Viewing: Codewalkers Forums > Other Technologies > Client Side Things > Javascript radio button |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|