www.webdeveloper.com
Results 1 to 8 of 8

Thread: Help with Dynamic Forms

  1. #1
    Join Date
    Jun 2003
    Posts
    4

    Help with Dynamic Forms

    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.

    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.

    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.

    Here's what I have:

    Javascript:
    <SCRIPT LANGUAGE="JavaScript">
    function createForm(drivers) {
    data = "";
    inter = "'";
    if (drivers < 6 && drivers > -1) {
    for (i=1; i <= drivers; i++) {
    if (i < 10) spaces=" ";
    else spaces=" ";
    data = data + "<table><tr><td bgcolor='#F0F89D' colspan=2>DRIVER " + i + "</td></tr>"
    + "<tr><td>First Name: </td><td><input type='text' size=20 name=" + inter + "First Name" + i + inter + "'></td></tr>"
    + "<tr><td>Last Name: </td><td><input type='text' size=20 name=" + inter + "Last Name" + i + inter + "'></td></tr>"
    + "<tr><td>Date of Birth: </td><td><input type='text' size=20 name=" + inter + "Date of Birth" + i + inter + "'></td></tr>"
    + "<tr><td>Driver License #: </td><td><input type='text' size=20 name=" + inter + "Drivers License #" + i + inter + "'></td></tr>"
    + "<tr><td>Social Security Number: </td><td><input type='text' size=20 name=" + inter + "Social Security Number" + i + inter + "'></td></tr>"
    + "<tr><td>Occupation: </td><td><input type='text' size=20 name=" + inter + "Occupation" + i + inter + "'></td></tr></table>";

    }
    if (document.layers) {
    document.layers.cust.document.write(data);
    document.layers.cust.document.close();
    }
    else {
    if (document.all) {
    cust.innerHTML = data;
    }
    }
    }
    else {
    window.alert("Please select up to 5 entries.");
    }
    }
    // End -->
    </script>
    Here's the first form to determine how many drivers to add:
    <form name=counter><table width="400" border="0" align="center" cellpadding="2" cellspacing="0" bgcolor="#A10035">
    <tr>
    <td><table width="400" border="0" cellpadding="6" cellspacing="0" bgcolor="#FFFFFF">
    <tr>
    <td width="325">How many drivers in your household?</td>
    <td width="25"><input type=text name=drivers size=5></td>
    </tr>
    <tr>
    <td colspan="2"><input name="button" type=button onClick="createForm(counter.drivers.value);" value="Update"></td>
    </tr>
    </table></td>
    </tr>
    </table></form>
    And finally, here is the form that displays the driver info:
    <form name="webform" method="post" action="cgi-bin/formMail.pl">
    <table border=0 cellpadding="4">
    <tr valign=top>
    <td colspan="2" bgcolor="#8B0027" class="whiteBold">Step 2 - Application</td>
    </tr>
    <tr><td colspan=2>

    <!-- Placeholder for dynamic form contents -->
    <span id=cust style="position:relative;"></span>

    </td></tr>
    <tr>
    <td></td>
    <td><input type=submit value="Send"></td>
    </tr>
    </table>
    </form>
    Any help would be appreciated. Thanks!

  2. #2
    Join Date
    Nov 2002
    Location
    Auburn, AL
    Posts
    9,222
    part of the problem is you are using java script to do it.

  3. #3
    Join Date
    Jun 2003
    Posts
    4
    Originally posted by PeOfEo
    part of the problem is you are using java script to do it.
    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.

    If you're implying that it can't be done with JavaScript, then how else could it be done?

    Or are you saying it can' be done?

    Or are you just trolling?

  4. #4
    Join Date
    Jan 2003
    Location
    USA
    Posts
    687
    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.


    To: webmaster@cycocity.com
    From: ()
    Subject: WWW Form Submission

    Below is the result of your feedback form. It was submitted by
    () on Friday, January 9, 2004 at 11:57:52
    ---------------------------------------------------------------------------

    First Name1: xcfcgxfkNUMBER1

    Last Name1: cykcgyk

    Date of Birth1: ykcgk

    Drivers License #1: kcgk

    Social Security Number1: kgck

    Occupation1: kcghk

    First Name2: NUMBER 2

    Last Name2: cvhmch

    Date of Birth2: cxvjkcv

    Drivers License #2: jcg

    Social Security Number2: xjc

    Occupation2: jcvh

    First Name3: NUMBER3

    Last Name3: xftjxfj

    Date of Birth3: fjcxfgjh

    Drivers License #3: fxcjcxfgj

    Social Security Number3: jxfj

    Occupation3: jxfjxfyjk

    ---------------------------------------------------------------------------

  5. #5
    Join Date
    Jun 2003
    Posts
    4
    Aaaarrrrrggggghhhhhh!!!!

    It's not fair! [/rant]

    Thanks for checking, CyCo. Your reply got me to thinking about different versions of formMail being a possibility, and from there to browser versions.

    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.

    Bummer!

    Since I like to code for the lowest common denominator I guess I'll have to just hard code in extra fields.

    Thanks for checking this out for me, I appreciate it!
    Last edited by RTMac; 01-09-2004 at 01:51 PM.

  6. #6
    Join Date
    Nov 2002
    Location
    Auburn, AL
    Posts
    9,222
    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.

  7. #7
    Join Date
    Jun 2003
    Posts
    4
    Good points. Thanks, PeOfEo

  8. #8
    Join Date
    Nov 2002
    Location
    Auburn, AL
    Posts
    9,222
    I am full of them, no one seems to ever realize that

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles