synaptyx
07-05-2007, 12:27 PM
Hi folks, first question here. I'm developing a registration form for a site and have no problem getting a form working, the bit I have no clue about is this dropdown part.
What I want is a dropdown with the numbers 1-10 in the list. When 1 is selected it shows 1 section of the reg form, when 5 is selected it shows 5 reg form sections, etc.
The other annoying part is that there are fields requiring validation throughout the form (they'll be more complex than the basic one below), but obviously, if a section is hidden I don't want a validation error for a field you cannot see.
What I've done so far is to build the form with the dropdown at the top and the 10 sections with the validation fields inside <div> tags with ids, but I have no clue how to implement the code needed to do show a number of sections by the choice in the dropdown.
I'm sure something like this has been done before, but having searched around here and the web, I haven't found something that matches exactly. I did find something similar, but I'm not a JS programmer, I have very little experience of looking at JS, so major handholding is needed.
Thanks for reading! :)
This is the HTML form with validation js autogenerated by FrontPage (yes I know, but it's handy for form building):
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Language" content="en-gb">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Conference registrations Registration</title>
</head>
<body>
<!--webbot BOT="GeneratedScript" PREVIEW=" " startspan --><script Language="JavaScript" Type="text/javascript"><!--
function Validator(theForm)
{
if (theForm.firstname1.value == "")
{
alert("Please enter a value for the \"firstname1\" field.");
theForm.firstname1.focus();
return (false);
}
if (theForm.surname1.value == "")
{
alert("Please enter a value for the \"surname1\" field.");
theForm.surname1.focus();
return (false);
}
if (theForm.firstname2.value == "")
{
alert("Please enter a value for the \"firstname2\" field.");
theForm.firstname2.focus();
return (false);
}
if (theForm.surname2.value == "")
{
alert("Please enter a value for the \"surname2\" field.");
theForm.surname2.focus();
return (false);
}
if (theForm.firstname3.value == "")
{
alert("Please enter a value for the \"firstname3\" field.");
theForm.firstname3.focus();
return (false);
}
if (theForm.surname3.value == "")
{
alert("Please enter a value for the \"surname3\" field.");
theForm.surname3.focus();
return (false);
}
if (theForm.firstname4.value == "")
{
alert("Please enter a value for the \"firstname4\" field.");
theForm.firstname4.focus();
return (false);
}
if (theForm.surname4.value == "")
{
alert("Please enter a value for the \"surname4\" field.");
theForm.surname4.focus();
return (false);
}
if (theForm.firstname5.value == "")
{
alert("Please enter a value for the \"firstname5\" field.");
theForm.firstname5.focus();
return (false);
}
if (theForm.surname5.value == "")
{
alert("Please enter a value for the \"surname5\" field.");
theForm.surname5.focus();
return (false);
}
if (theForm.firstname6.value == "")
{
alert("Please enter a value for the \"firstname6\" field.");
theForm.firstname6.focus();
return (false);
}
if (theForm.surname6.value == "")
{
alert("Please enter a value for the \"surname6\" field.");
theForm.surname6.focus();
return (false);
}
if (theForm.firstname7.value == "")
{
alert("Please enter a value for the \"firstname7\" field.");
theForm.firstname7.focus();
return (false);
}
if (theForm.surname7.value == "")
{
alert("Please enter a value for the \"surname7\" field.");
theForm.surname7.focus();
return (false);
}
if (theForm.firstname8.value == "")
{
alert("Please enter a value for the \"firstname8\" field.");
theForm.firstname8.focus();
return (false);
}
if (theForm.surname8.value == "")
{
alert("Please enter a value for the \"surname8\" field.");
theForm.surname8.focus();
return (false);
}
if (theForm.firstname9.value == "")
{
alert("Please enter a value for the \"firstname9\" field.");
theForm.firstname9.focus();
return (false);
}
if (theForm.surname9.value == "")
{
alert("Please enter a value for the \"surname9\" field.");
theForm.surname9.focus();
return (false);
}
if (theForm.firstname10.value == "")
{
alert("Please enter a value for the \"firstname10\" field.");
theForm.firstname10.focus();
return (false);
}
if (theForm.surname10.value == "")
{
alert("Please enter a value for the \"surname10\" field.");
theForm.surname10.focus();
return (false);
}
return (true);
}
//--></script><!--webbot BOT="GeneratedScript" endspan --><form method="post" action="regformhandler.php" onsubmit="return Validator(this)" language="JavaScript" name="regform">
<table id="topTable" border="0" width="100%">
<tr>
<td>No. of Registrations: <select size="1" name="numberofreg">
<option>--</option>
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
<option>6</option>
<option>7</option>
<option>8</option>
<option>9</option>
<option>10</option>
</select></td>
</tr>
</table>
<div id="registration01">
<table id="1st" border="0" width="100%">
<tr>
<td colspan="2">
<hr></td>
</tr>
<tr>
<td colspan="2">Registration 1</td>
</tr>
<tr>
<td>Title:</td>
<td><input name="title1" size="10" type="text"></td>
</tr>
<tr>
<td>First Name:</td>
<td><!--webbot bot="Validation" b-value-required="TRUE" --><input name="firstname1" size="20" type="text">*</td>
</tr>
<tr>
<td>Surname:</td>
<td><!--webbot bot="Validation" b-value-required="TRUE" --><input name="surname1" size="20" type="text">*</td>
</tr>
</table>
</div>
<div id="registration02">
<table id="2nd" border="0" width="100%">
<tr>
<td colspan="2">
<hr></td>
</tr>
<tr>
<td colspan="2">Registration 2</td>
</tr>
<tr>
<td>Title:</td>
<td><input name="title2" size="10" type="text"></td>
</tr>
<tr>
<td>First Name:</td>
<td><!--webbot bot="Validation" b-value-required="TRUE" --><input name="firstname2" size="20" type="text">*</td>
</tr>
<tr>
<td>Surname:</td>
<td><!--webbot bot="Validation" b-value-required="TRUE" --><input name="surname2" size="20" type="text">*</td>
</tr>
</table>
</div>
<div id="registration03">
<table id="3rd" border="0" width="100%">
<tr>
<td colspan="2">
<hr></td>
</tr>
<tr>
<td colspan="2">Registration 3</td>
</tr>
<tr>
<td>Title:</td>
<td><input name="title3" size="10" type="text"></td>
</tr>
<tr>
<td>First Name:</td>
<td><!--webbot bot="Validation" b-value-required="TRUE" --><input name="firstname3" size="20" type="text">*</td>
</tr>
<tr>
<td>Surname:</td>
<td><!--webbot bot="Validation" b-value-required="TRUE" --><input name="surname3" size="20" type="text">*</td>
</tr>
</table>
</div>
<div id="registration04">
<table id="4th" border="0" width="100%">
<tr>
<td colspan="2">
<hr></td>
</tr>
<tr>
<td colspan="2">Registration 4</td>
</tr>
<tr>
<td>Title:</td>
<td><input name="title4" size="10" type="text"></td>
</tr>
<tr>
<td>First Name:</td>
<td><!--webbot bot="Validation" b-value-required="TRUE" --><input name="firstname4" size="20" type="text">*</td>
</tr>
<tr>
<td>Surname:</td>
<td><!--webbot bot="Validation" b-value-required="TRUE" --><input name="surname4" size="20" type="text">*</td>
</tr>
</table>
</div>
<div id="registration05">
<table id="5th" border="0" width="100%">
<tr>
<td colspan="2">
<hr></td>
</tr>
<tr>
<td colspan="2">Registration 5</td>
</tr>
<tr>
<td>Title:</td>
<td><input name="title5" size="10" type="text"></td>
</tr>
<tr>
<td>First Name:</td>
<td><!--webbot bot="Validation" b-value-required="TRUE" --><input name="firstname5" size="20" type="text">*</td>
</tr>
<tr>
<td>Surname:</td>
<td><!--webbot bot="Validation" b-value-required="TRUE" --><input name="surname5" size="20" type="text">*</td>
</tr>
</table>
</div>
<div id="attndee06">
<table id="6th" border="0" width="100%">
<tr>
<td colspan="2">
<hr></td>
</tr>
<tr>
<td colspan="2">Registration 6</td>
</tr>
<tr>
<td>Title:</td>
<td><input name="title6" size="10" type="text"></td>
</tr>
<tr>
<td>First Name:</td>
<td><!--webbot bot="Validation" b-value-required="TRUE" --><input name="firstname6" size="20" type="text">*</td>
</tr>
<tr>
<td>Surname:</td>
<td><!--webbot bot="Validation" b-value-required="TRUE" --><input name="surname6" size="20" type="text">*</td>
</tr>
</table>
</div>
<div id="registration07">
<table id="7th" border="0" width="100%">
<tr>
<td colspan="2">
<hr></td>
</tr>
<tr>
<td colspan="2">Registration 7</td>
</tr>
<tr>
<td>Title:</td>
<td><input name="title7" size="10" type="text"></td>
</tr>
<tr>
<td>First Name:</td>
<td><!--webbot bot="Validation" b-value-required="TRUE" --><input name="firstname7" size="20" type="text">*</td>
</tr>
<tr>
<td>Surname:</td>
<td><!--webbot bot="Validation" b-value-required="TRUE" --><input name="surname7" size="20" type="text">*</td>
</tr>
</table>
</div>
<div id="registration08">
<table id="8th" border="0" width="100%">
<tr>
<td colspan="2">
<hr></td>
</tr>
<tr>
<td colspan="2">Registration 8</td>
</tr>
<tr>
<td>Title:</td>
<td><input name="title8" size="10" type="text"></td>
</tr>
<tr>
<td>First Name:</td>
<td><!--webbot bot="Validation" b-value-required="TRUE" --><input name="firstname8" size="20" type="text">*</td>
</tr>
<tr>
<td>Surname:</td>
<td><!--webbot bot="Validation" b-value-required="TRUE" --><input name="surname8" size="20" type="text">*</td>
</tr>
</table>
</div>
<div id="registration09">
<table id="9th" border="0" width="100%">
<tr>
<td colspan="2">
<hr></td>
</tr>
<tr>
<td colspan="2">Registration 9</td>
</tr>
<tr>
<td>Title:</td>
<td><input name="title9" size="10" type="text"></td>
</tr>
<tr>
<td>First Name:</td>
<td><!--webbot bot="Validation" b-value-required="TRUE" --><input name="firstname9" size="20" type="text">*</td>
</tr>
<tr>
<td>Surname:</td>
<td><!--webbot bot="Validation" b-value-required="TRUE" --><input name="surname9" size="20" type="text">*</td>
</tr>
</table>
</div>
<div id="registration10">
<table id="10th" border="0" width="100%">
<tr>
<td colspan="2">
<hr></td>
</tr>
<tr>
<td colspan="2">Registration 10</td>
</tr>
<tr>
<td>Title:</td>
<td><input name="title10" size="10" type="text"></td>
</tr>
<tr>
<td>First Name:</td>
<td><!--webbot bot="Validation" b-value-required="TRUE" --><input name="firstname10" size="20" type="text">*</td>
</tr>
<tr>
<td>Surname:</td>
<td><!--webbot bot="Validation" b-value-required="TRUE" --><input name="surname10" size="20" type="text">*</td>
</tr>
</table>
</div>
<table id="buttons" border="0" cellpadding="0" width="100%">
<tr>
<td><input value="Send" name="send" type="submit"><input value="Reset" name="reset" type="reset"></td>
</tr>
</table>
</form>
</body>
</html>
What I want is a dropdown with the numbers 1-10 in the list. When 1 is selected it shows 1 section of the reg form, when 5 is selected it shows 5 reg form sections, etc.
The other annoying part is that there are fields requiring validation throughout the form (they'll be more complex than the basic one below), but obviously, if a section is hidden I don't want a validation error for a field you cannot see.
What I've done so far is to build the form with the dropdown at the top and the 10 sections with the validation fields inside <div> tags with ids, but I have no clue how to implement the code needed to do show a number of sections by the choice in the dropdown.
I'm sure something like this has been done before, but having searched around here and the web, I haven't found something that matches exactly. I did find something similar, but I'm not a JS programmer, I have very little experience of looking at JS, so major handholding is needed.
Thanks for reading! :)
This is the HTML form with validation js autogenerated by FrontPage (yes I know, but it's handy for form building):
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Language" content="en-gb">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Conference registrations Registration</title>
</head>
<body>
<!--webbot BOT="GeneratedScript" PREVIEW=" " startspan --><script Language="JavaScript" Type="text/javascript"><!--
function Validator(theForm)
{
if (theForm.firstname1.value == "")
{
alert("Please enter a value for the \"firstname1\" field.");
theForm.firstname1.focus();
return (false);
}
if (theForm.surname1.value == "")
{
alert("Please enter a value for the \"surname1\" field.");
theForm.surname1.focus();
return (false);
}
if (theForm.firstname2.value == "")
{
alert("Please enter a value for the \"firstname2\" field.");
theForm.firstname2.focus();
return (false);
}
if (theForm.surname2.value == "")
{
alert("Please enter a value for the \"surname2\" field.");
theForm.surname2.focus();
return (false);
}
if (theForm.firstname3.value == "")
{
alert("Please enter a value for the \"firstname3\" field.");
theForm.firstname3.focus();
return (false);
}
if (theForm.surname3.value == "")
{
alert("Please enter a value for the \"surname3\" field.");
theForm.surname3.focus();
return (false);
}
if (theForm.firstname4.value == "")
{
alert("Please enter a value for the \"firstname4\" field.");
theForm.firstname4.focus();
return (false);
}
if (theForm.surname4.value == "")
{
alert("Please enter a value for the \"surname4\" field.");
theForm.surname4.focus();
return (false);
}
if (theForm.firstname5.value == "")
{
alert("Please enter a value for the \"firstname5\" field.");
theForm.firstname5.focus();
return (false);
}
if (theForm.surname5.value == "")
{
alert("Please enter a value for the \"surname5\" field.");
theForm.surname5.focus();
return (false);
}
if (theForm.firstname6.value == "")
{
alert("Please enter a value for the \"firstname6\" field.");
theForm.firstname6.focus();
return (false);
}
if (theForm.surname6.value == "")
{
alert("Please enter a value for the \"surname6\" field.");
theForm.surname6.focus();
return (false);
}
if (theForm.firstname7.value == "")
{
alert("Please enter a value for the \"firstname7\" field.");
theForm.firstname7.focus();
return (false);
}
if (theForm.surname7.value == "")
{
alert("Please enter a value for the \"surname7\" field.");
theForm.surname7.focus();
return (false);
}
if (theForm.firstname8.value == "")
{
alert("Please enter a value for the \"firstname8\" field.");
theForm.firstname8.focus();
return (false);
}
if (theForm.surname8.value == "")
{
alert("Please enter a value for the \"surname8\" field.");
theForm.surname8.focus();
return (false);
}
if (theForm.firstname9.value == "")
{
alert("Please enter a value for the \"firstname9\" field.");
theForm.firstname9.focus();
return (false);
}
if (theForm.surname9.value == "")
{
alert("Please enter a value for the \"surname9\" field.");
theForm.surname9.focus();
return (false);
}
if (theForm.firstname10.value == "")
{
alert("Please enter a value for the \"firstname10\" field.");
theForm.firstname10.focus();
return (false);
}
if (theForm.surname10.value == "")
{
alert("Please enter a value for the \"surname10\" field.");
theForm.surname10.focus();
return (false);
}
return (true);
}
//--></script><!--webbot BOT="GeneratedScript" endspan --><form method="post" action="regformhandler.php" onsubmit="return Validator(this)" language="JavaScript" name="regform">
<table id="topTable" border="0" width="100%">
<tr>
<td>No. of Registrations: <select size="1" name="numberofreg">
<option>--</option>
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
<option>6</option>
<option>7</option>
<option>8</option>
<option>9</option>
<option>10</option>
</select></td>
</tr>
</table>
<div id="registration01">
<table id="1st" border="0" width="100%">
<tr>
<td colspan="2">
<hr></td>
</tr>
<tr>
<td colspan="2">Registration 1</td>
</tr>
<tr>
<td>Title:</td>
<td><input name="title1" size="10" type="text"></td>
</tr>
<tr>
<td>First Name:</td>
<td><!--webbot bot="Validation" b-value-required="TRUE" --><input name="firstname1" size="20" type="text">*</td>
</tr>
<tr>
<td>Surname:</td>
<td><!--webbot bot="Validation" b-value-required="TRUE" --><input name="surname1" size="20" type="text">*</td>
</tr>
</table>
</div>
<div id="registration02">
<table id="2nd" border="0" width="100%">
<tr>
<td colspan="2">
<hr></td>
</tr>
<tr>
<td colspan="2">Registration 2</td>
</tr>
<tr>
<td>Title:</td>
<td><input name="title2" size="10" type="text"></td>
</tr>
<tr>
<td>First Name:</td>
<td><!--webbot bot="Validation" b-value-required="TRUE" --><input name="firstname2" size="20" type="text">*</td>
</tr>
<tr>
<td>Surname:</td>
<td><!--webbot bot="Validation" b-value-required="TRUE" --><input name="surname2" size="20" type="text">*</td>
</tr>
</table>
</div>
<div id="registration03">
<table id="3rd" border="0" width="100%">
<tr>
<td colspan="2">
<hr></td>
</tr>
<tr>
<td colspan="2">Registration 3</td>
</tr>
<tr>
<td>Title:</td>
<td><input name="title3" size="10" type="text"></td>
</tr>
<tr>
<td>First Name:</td>
<td><!--webbot bot="Validation" b-value-required="TRUE" --><input name="firstname3" size="20" type="text">*</td>
</tr>
<tr>
<td>Surname:</td>
<td><!--webbot bot="Validation" b-value-required="TRUE" --><input name="surname3" size="20" type="text">*</td>
</tr>
</table>
</div>
<div id="registration04">
<table id="4th" border="0" width="100%">
<tr>
<td colspan="2">
<hr></td>
</tr>
<tr>
<td colspan="2">Registration 4</td>
</tr>
<tr>
<td>Title:</td>
<td><input name="title4" size="10" type="text"></td>
</tr>
<tr>
<td>First Name:</td>
<td><!--webbot bot="Validation" b-value-required="TRUE" --><input name="firstname4" size="20" type="text">*</td>
</tr>
<tr>
<td>Surname:</td>
<td><!--webbot bot="Validation" b-value-required="TRUE" --><input name="surname4" size="20" type="text">*</td>
</tr>
</table>
</div>
<div id="registration05">
<table id="5th" border="0" width="100%">
<tr>
<td colspan="2">
<hr></td>
</tr>
<tr>
<td colspan="2">Registration 5</td>
</tr>
<tr>
<td>Title:</td>
<td><input name="title5" size="10" type="text"></td>
</tr>
<tr>
<td>First Name:</td>
<td><!--webbot bot="Validation" b-value-required="TRUE" --><input name="firstname5" size="20" type="text">*</td>
</tr>
<tr>
<td>Surname:</td>
<td><!--webbot bot="Validation" b-value-required="TRUE" --><input name="surname5" size="20" type="text">*</td>
</tr>
</table>
</div>
<div id="attndee06">
<table id="6th" border="0" width="100%">
<tr>
<td colspan="2">
<hr></td>
</tr>
<tr>
<td colspan="2">Registration 6</td>
</tr>
<tr>
<td>Title:</td>
<td><input name="title6" size="10" type="text"></td>
</tr>
<tr>
<td>First Name:</td>
<td><!--webbot bot="Validation" b-value-required="TRUE" --><input name="firstname6" size="20" type="text">*</td>
</tr>
<tr>
<td>Surname:</td>
<td><!--webbot bot="Validation" b-value-required="TRUE" --><input name="surname6" size="20" type="text">*</td>
</tr>
</table>
</div>
<div id="registration07">
<table id="7th" border="0" width="100%">
<tr>
<td colspan="2">
<hr></td>
</tr>
<tr>
<td colspan="2">Registration 7</td>
</tr>
<tr>
<td>Title:</td>
<td><input name="title7" size="10" type="text"></td>
</tr>
<tr>
<td>First Name:</td>
<td><!--webbot bot="Validation" b-value-required="TRUE" --><input name="firstname7" size="20" type="text">*</td>
</tr>
<tr>
<td>Surname:</td>
<td><!--webbot bot="Validation" b-value-required="TRUE" --><input name="surname7" size="20" type="text">*</td>
</tr>
</table>
</div>
<div id="registration08">
<table id="8th" border="0" width="100%">
<tr>
<td colspan="2">
<hr></td>
</tr>
<tr>
<td colspan="2">Registration 8</td>
</tr>
<tr>
<td>Title:</td>
<td><input name="title8" size="10" type="text"></td>
</tr>
<tr>
<td>First Name:</td>
<td><!--webbot bot="Validation" b-value-required="TRUE" --><input name="firstname8" size="20" type="text">*</td>
</tr>
<tr>
<td>Surname:</td>
<td><!--webbot bot="Validation" b-value-required="TRUE" --><input name="surname8" size="20" type="text">*</td>
</tr>
</table>
</div>
<div id="registration09">
<table id="9th" border="0" width="100%">
<tr>
<td colspan="2">
<hr></td>
</tr>
<tr>
<td colspan="2">Registration 9</td>
</tr>
<tr>
<td>Title:</td>
<td><input name="title9" size="10" type="text"></td>
</tr>
<tr>
<td>First Name:</td>
<td><!--webbot bot="Validation" b-value-required="TRUE" --><input name="firstname9" size="20" type="text">*</td>
</tr>
<tr>
<td>Surname:</td>
<td><!--webbot bot="Validation" b-value-required="TRUE" --><input name="surname9" size="20" type="text">*</td>
</tr>
</table>
</div>
<div id="registration10">
<table id="10th" border="0" width="100%">
<tr>
<td colspan="2">
<hr></td>
</tr>
<tr>
<td colspan="2">Registration 10</td>
</tr>
<tr>
<td>Title:</td>
<td><input name="title10" size="10" type="text"></td>
</tr>
<tr>
<td>First Name:</td>
<td><!--webbot bot="Validation" b-value-required="TRUE" --><input name="firstname10" size="20" type="text">*</td>
</tr>
<tr>
<td>Surname:</td>
<td><!--webbot bot="Validation" b-value-required="TRUE" --><input name="surname10" size="20" type="text">*</td>
</tr>
</table>
</div>
<table id="buttons" border="0" cellpadding="0" width="100%">
<tr>
<td><input value="Send" name="send" type="submit"><input value="Reset" name="reset" type="reset"></td>
</tr>
</table>
</form>
</body>
</html>