SunJune
12-20-2010, 05:32 PM
Hi,
I am trying to use the radio button to display the information for the users. For example, when I click radio button "1", the form should display 1 text box each for first name, last name and so on. When the user clicks on radio button 2, there should be text boxes displayed for user 1 and user 2 to enter their info(first name, last name and so on).
I looked at the forum, but couldn't find something similiar.Please advise.
Something like
================================
Number of Users 1 2 3
# if radio button 2 is selected then
User 1
First Name
Last Name
User 2
First Name
Last Name
================================
The code is as below:
<html>
<head>
<script type="text/javascript">
function showUser()
{
for(i=0;i<document.form.users.length;i++)
{
if (document.form.users[i].checked)
val=parseInt(document.form.users[i].value);
for(j=0;j<=val;j++)
{
document.form.write("<table cellSpacing=1 cellPadding=0 width=600 border=0>");
document.form.write("<tr>
<td width='20%' align='right'><font color="#660000"><b>First Name: </b></font></td>");
document.form.write("<td><input type='text' name='fname1' size='25' maxlength='25'></td></tr>");
document.form.write("<tr><td width='20%' align='right'><font color="#660000"><b>Last Name: </b></font></td>");
document.form.write("<td><input type='text' name='lname1' size='25'maxlength='25'></td></tr>");
document.form.write("</table>");
}
}
}
</script>
</head>
<form>
Check the number of users to display additional input fields.<br><br>
<input type="radio" name="users" value="1" onclick = "showUser()"/> 1<br/>
<input type="radio" name="users" value="2" onclick = "showUser()"/>2 <br/>
<input type="radio" name="users" value="3" onclick = "showUser()"/>3 <br/>
</form>
</html>
========================================================
Thanks in advance.
I am trying to use the radio button to display the information for the users. For example, when I click radio button "1", the form should display 1 text box each for first name, last name and so on. When the user clicks on radio button 2, there should be text boxes displayed for user 1 and user 2 to enter their info(first name, last name and so on).
I looked at the forum, but couldn't find something similiar.Please advise.
Something like
================================
Number of Users 1 2 3
# if radio button 2 is selected then
User 1
First Name
Last Name
User 2
First Name
Last Name
================================
The code is as below:
<html>
<head>
<script type="text/javascript">
function showUser()
{
for(i=0;i<document.form.users.length;i++)
{
if (document.form.users[i].checked)
val=parseInt(document.form.users[i].value);
for(j=0;j<=val;j++)
{
document.form.write("<table cellSpacing=1 cellPadding=0 width=600 border=0>");
document.form.write("<tr>
<td width='20%' align='right'><font color="#660000"><b>First Name: </b></font></td>");
document.form.write("<td><input type='text' name='fname1' size='25' maxlength='25'></td></tr>");
document.form.write("<tr><td width='20%' align='right'><font color="#660000"><b>Last Name: </b></font></td>");
document.form.write("<td><input type='text' name='lname1' size='25'maxlength='25'></td></tr>");
document.form.write("</table>");
}
}
}
</script>
</head>
<form>
Check the number of users to display additional input fields.<br><br>
<input type="radio" name="users" value="1" onclick = "showUser()"/> 1<br/>
<input type="radio" name="users" value="2" onclick = "showUser()"/>2 <br/>
<input type="radio" name="users" value="3" onclick = "showUser()"/>3 <br/>
</form>
</html>
========================================================
Thanks in advance.