Page 1 of 1

submit form with dynamic number fo fields

Posted: Fri Jun 11, 2004 1:59 pm
by kcomer
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:

Code: Select all

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++) &#123;
		var tbl = document.getElementById('membersTable').insertRow(shown);
		var cell1 = tbl.insertCell(0);
		cell1.className = 'form-display';
		cell1.innerHTML = '<input type="text" name="hhmembers&#1111;]&#1111;last]" size="13" value="" onFocus="window.status=''Enter the Household Members Last Name'';style.backgroundColor=''#E9F8E2'';" onBlur="style.backgroundColor=''#ffffff'';window.status='''';" />';
	&#125;
&#125;
I am calling the function from another text box using the onBlur event. Like so

Code: Select all

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

Posted: Fri Jun 11, 2004 3:58 pm
by scorphus
Hello kcomer, nice trick!

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

Scorphus.

Posted: Mon Jun 14, 2004 9:00 am
by kcomer
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.

Posted: Mon Jun 14, 2004 9:15 am
by kcomer
Followup:

I had a table nested within a table, like so.

Code: Select all

<form>
<table>
<tr>
	<td>
		<table>
		<tr>
			<td></td>
		</tr>
		</table>
	</td>
</tr>
</table>
</form>
When I moved the form tags inside the table it worked fine, like this.

Code: Select all

<table>
<tr>
	<td>
		<form>
		<table>
		<tr>
			<td></td>
		</tr>
		</table>
		</form>
	</td>
</tr>
</table>
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