Help with Dynamic Forms

liunx

Guest
I need to create a form that adds multiple fields depending on user input, and then have the results sent to my formMail.pl script.<br />
<br />
Here's an example: an insurance company form for auto insurance. The first thing they want to know is how many drivers in the household. The form will then display fields for name, drivers licence number, etc. for each driver in the household.<br />
<br />
I have found some code that updates the form correctly, but it doesn't pass the dynamic form variables to the formmail script. The email gets sent, but the dynamic form fields are blank.<br />
<br />
Here's what I have:<br />
<br />
Javascript:<br />
<SCRIPT LANGUAGE="JavaScript"><br />
function createForm(drivers) {<br />
data = ""; <br />
inter = "'";<br />
if (drivers < 6 && drivers > -1) {<br />
for (i=1; i <= drivers; i++) {<br />
if (i < 10) spaces=" ";<br />
else spaces=" ";<br />
data = data + "<table><tr><td bgcolor='#F0F89D' colspan=2>DRIVER " + i + "</td></tr>"<br />
+ "<tr><td>First Name: </td><td><input type='text' size=20 name=" + inter + "First Name" + i + inter + "'></td></tr>"<br />
+ "<tr><td>Last Name: </td><td><input type='text' size=20 name=" + inter + "Last Name" + i + inter + "'></td></tr>"<br />
+ "<tr><td>Date of Birth: </td><td><input type='text' size=20 name=" + inter + "Date of Birth" + i + inter + "'></td></tr>"<br />
+ "<tr><td>Driver License #: </td><td><input type='text' size=20 name=" + inter + "Drivers License #" + i + inter + "'></td></tr>"<br />
+ "<tr><td>Social Security Number: </td><td><input type='text' size=20 name=" + inter + "Social Security Number" + i + inter + "'></td></tr>"<br />
+ "<tr><td>Occupation: </td><td><input type='text' size=20 name=" + inter + "Occupation" + i + inter + "'></td></tr></table>";<br />
<br />
}<br />
if (document.layers) {<br />
document.layers.cust.document.write(data);<br />
document.layers.cust.document.close();<br />
}<br />
else {<br />
if (document.all) {<br />
cust.innerHTML = data;<br />
}<br />
}<br />
}<br />
else {<br />
window.alert("Please select up to 5 entries.");<br />
}<br />
}<br />
// End --><br />
</script> <br />
<br />
Here's the first form to determine how many drivers to add:<br />
<form name=counter><table width="400" border="0" align="center" cellpadding="2" cellspacing="0" bgcolor="#A10035"><br />
<tr><br />
<td><table width="400" border="0" cellpadding="6" cellspacing="0" bgcolor="#FFFFFF"><br />
<tr><br />
<td width="325">How many drivers in your household?</td><br />
<td width="25"><input type=text name=drivers size=5></td><br />
</tr><br />
<tr><br />
<td colspan="2"><input name="button" type=button onClick="createForm(counter.drivers.value);" value="Update"></td><br />
</tr><br />
</table></td><br />
</tr><br />
</table></form> <br />
<br />
And finally, here is the form that displays the driver info:<br />
<form name="webform" method="post" action="cgi-bin/formMail.pl"><br />
<table border=0 cellpadding="4"><br />
<tr valign=top><br />
<td colspan="2" bgcolor="#8B0027" class="whiteBold">Step 2 - Application</td><br />
</tr><br />
<tr><td colspan=2><br />
<br />
<!-- Placeholder for dynamic form contents --><br />
<span id=cust style="position:relative;"></span><br />
<br />
</td></tr><br />
<tr><br />
<td></td><br />
<td><input type=submit value="Send"></td><br />
</tr><br />
</table><br />
</form> <br />
<br />
Any help would be appreciated. Thanks!<!--content-->part of the problem is you are using java script to do it.<!--content-->Originally posted by PeOfEo <br />
part of the problem is you are using java script to do it. <br />
<br />
If you're implying that I should be posting in the JavaScript forum, I apologize for that - I was viewing the real issue as being with the form code.<br />
<br />
If you're implying that it can't be done with JavaScript, then how else could it be done?<br />
<br />
Or are you saying it can' be done?<br />
<br />
Or are you just trolling?<!--content-->well, I used your exact form and tested it on my server using FormMail.pl and it worked just fine. Below is the output of the form. *note*, I just pecked in whatever in the generated boxes, so it's giberish...but it does work.<br />
<br />
<br />
To: <!-- e --><a href="mailto:[email protected]">[email protected]</a><!-- e --><br />
From: ()<br />
Subject: WWW Form Submission<br />
<br />
Below is the result of your feedback form. It was submitted by<br />
() on Friday, January 9, 2004 at 11:57:52<br />
---------------------------------------------------------------------------<br />
<br />
First Name1: xcfcgxfkNUMBER1<br />
<br />
Last Name1: cykcgyk<br />
<br />
Date of Birth1: ykcgk<br />
<br />
Drivers License #1: kcgk<br />
<br />
Social Security Number1: kgck<br />
<br />
Occupation1: kcghk<br />
<br />
First Name2: NUMBER 2<br />
<br />
Last Name2: cvhmch<br />
<br />
Date of Birth2: cxvjkcv<br />
<br />
Drivers License #2: jcg<br />
<br />
Social Security Number2: xjc<br />
<br />
Occupation2: jcvh<br />
<br />
First Name3: NUMBER3<br />
<br />
Last Name3: xftjxfj<br />
<br />
Date of Birth3: fjcxfgjh<br />
<br />
Drivers License #3: fxcjcxfgj<br />
<br />
Social Security Number3: jxfj<br />
<br />
Occupation3: jxfjxfyjk<br />
<br />
---------------------------------------------------------------------------<!--content-->Aaaarrrrrggggghhhhhh!!!! <br />
<br />
It's not fair! [/rant]<br />
<br />
Thanks for checking, CyCo. Your reply got me to thinking about different versions of formMail being a possibility, and from there to browser versions.<br />
<br />
So I did some browser testing. It turns out that my code won't work on IE 5.5 browsers, only on 6.0 versions.<br />
<br />
Bummer!<br />
<br />
Since I like to code for the lowest common denominator I guess I'll have to just hard code in extra fields.<br />
<br />
Thanks for checking this out for me, I appreciate it!<!--content-->I would not use javascript at all is what I was saying before. I do everything with forms server side. ASP PHP CGI ASP.NET JSP CF. It is more secure and don't forget that 13% of the internet does not support javascript. Furthermore it would probably lag less to do it server side.<!--content-->Good points. Thanks, PeOfEo<!--content-->I am full of them, no one seems to ever realize that :D<!--content-->
 
Back
Top