[solved]html forms array and javascript array

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
mushi
Forum Newbie
Posts: 8
Joined: Mon Jun 27, 2005 1:34 pm

[solved]html forms array and javascript array

Post by mushi »

I have a simple form that generated another set of forms depending on how customers are entered.

First form: how many customer?

Second file: If the answer is 2, it generated 2 forms with exactly the same fields. It's stored in an array.
My question is how to have javascript read the values in that array. Thanks!!

Here's a sample of the 2nd file.

Code: Select all

echo "<form name='totalcomp' action='average2.php' method='POST'>";
	for ($i=0; $i<$number; $i++)
	{
?>

	
	<fieldset style="width:300px; height:150px"><legend>Compute Average</legend>
	<div id = "box2">
	<table border = "0">
		<tr>
			<td>&nbsp;</td>
			<td>&nbsp;</td>
		</tr>
		<tr>
			<td>Number 1:</td>
			<td><input type="text" name="num1[]" /></td>
		</tr>
		<tr>
			<td>Number 2:</td>
			<td><input type="text" name="num2[]" /></td>
		</tr>
		<tr>
			<td>Total:</td>
			<td><input type="text" name="total[]" onBlur = "mytest()"/></td>
		</tr>
		
		

	</table>
	</div>
	</fieldset>
	<?}?>
	<tr>
		<td><input type="submit" name = "submit" value="submit" /></td>
		</tr>
	</form>
Last edited by mushi on Wed Feb 15, 2006 4:21 pm, edited 1 time in total.
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Re: html forms array and javascript array

Post by Weirdan »

mushi wrote: Second file: If the answer is 2, it generated 2 forms with exactly the same fields. It's stored in an array.
My question is how to have javascript read the values in that array. Thanks!!
Either give your fields distinct ids ('item1', 'item2' ...) and use document.getElementById or use document.getElementsByName
mushi
Forum Newbie
Posts: 8
Joined: Mon Jun 27, 2005 1:34 pm

Post by mushi »

Thank you for replying. I got it to works in IE, but it doesn't work in Firefox.
This is the error in firefox:

Error: document.getElementsByName("num1")[j] has no properties.

Is there a reason why it would work in one browser and not the other?
Post Reply