submit form with dynamic number fo fields

JavaScript and client side scripting.

Moderator: General Moderators

submit form with dynamic number fo fields

Postby kcomer » Fri Jun 11, 2004 1:59 pm

I have a form that needs a to show only a certain number fo fields based another value in the form. I wrote a javascript function to add the rows to the table that I need and then populate the cells with input fields. Here is the javascript function:
Syntax: [ Download ] [ Hide ]
function drawMembers(totalMembers)
{
        // Get the number of rows already shown for the hhmembers
        var shown = document.getElementById('membersTable').rows.length;
       
        for (i = shown; i <= totalMembers; i++) {
                var tbl = document.getElementById('membersTable').insertRow(shown);
                var cell1 = tbl.insertCell(0);
                cell1.className = 'form-display';
                cell1.innerHTML = '<input type="text" name="hhmembersї]їlast]" size="13" value="" onFocus="window.status=''Enter the Household Members Last Name'';style.backgroundColor=''#E9F8E2'';" onBlur="style.backgroundColor=''#ffffff'';window.status='''';" />';
        }
}


I am calling the function from another text box using the onBlur event. Like so
Syntax: [ Download ] [ Hide ]
onBlur="drawMembers(parent.document.intake.hhnum.value);"


I am not having a problem with the extra form fields being created on the page. The problem is that when I submit the form none of the fields added by my javascript function are shown. if I do a print_r($_POST) it lists all the fields excpet for the ones added after the page was loaded. Any ideas would be great. I would give a linkt o the page but it's on an internal only webserver.

PS This is my first big jump into using Javascript on my web apps so don't assume I know what I'm doing.

Thanks
kcomer
Forum Contributor
 
Posts: 108
Joined: Tue Aug 27, 2002 8:50 am

Postby scorphus » Fri Jun 11, 2004 3:58 pm

Hello kcomer, nice trick!

I got it working, tale a look: http://scorphus.no-ip.com/lab/dynamic_form.php

Scorphus.
User avatar
scorphus
Forum Regular
 
Posts: 589
Joined: Fri May 09, 2003 11:53 pm
Location: Belo Horizonte, Brazil

Postby kcomer » Mon Jun 14, 2004 9:00 am

I still can't get mine to work. I installed the Web Developer tools for Firefox wich let me see the form details. When I look at your form and update the field number it shows the added fields when I use the "View Form Information" from the Web Developer toolbar. When I try mine, it doesn't. Has anyone seen this behavior before? I tried your page on ym dev server and it worked fine so I know it's not my server or my client. It's acting like the form fields that I'm adding are being added after the </form> because they don't appear.
kcomer
Forum Contributor
 
Posts: 108
Joined: Tue Aug 27, 2002 8:50 am

Postby kcomer » Mon Jun 14, 2004 9:15 am

Followup:

I had a table nested within a table, like so.
Syntax: [ Download ] [ Hide ]
&lt;form&gt;
&lt;table&gt;
&lt;tr&gt;
        &lt;td&gt;
                &lt;table&gt;
                &lt;tr&gt;
                        &lt;td&gt;&lt;/td&gt;
                &lt;/tr&gt;
                &lt;/table&gt;
        &lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/form&gt;

When I moved the form tags inside the table it worked fine, like this.
Syntax: [ Download ] [ Hide ]
&lt;table&gt;
&lt;tr&gt;
        &lt;td&gt;
                &lt;form&gt;
                &lt;table&gt;
                &lt;tr&gt;
                        &lt;td&gt;&lt;/td&gt;
                &lt;/tr&gt;
                &lt;/table&gt;
                &lt;/form&gt;
        &lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;

Thanks for the help though. I atleast knew I had the right code, I may try this with IE and Safari later to see if it's a bug with Firefox or maybe just an html issue.

Thanks again.

Keith
kcomer
Forum Contributor
 
Posts: 108
Joined: Tue Aug 27, 2002 8:50 am


Return to Javascript

Who is online

Users browsing this forum: No registered users and 4 guests