[SMARTY] how to get javascript to read array in smarty
"Alyssa Phan" <[email protected]>
| Newsgroups | gmane.comp.php.smarty.general |
|---|---|
| Message-ID | <45057232A4AC6444B0F9452131E7446E0226C024@exchange.win2k.tsl.state.tx.us> |
Hi everyone,
I have a simple form that generated another set of forms depending on how many customers are entered.
First form: how many customers?
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. This is the error I get when running the program.
Error: document.getElementsByName("num1[]")[j] has no properties.
Here's an example of the second form:
{section name=ill start=1 loop=$customer+1 step=1}
<table border = "1">
<tr>
<td>Number 1:</td><td><input type="text" name="num1[{$smarty.section.ill.index}]" /></td></tr>
<tr><td>Number 2:</td><td><input type="text" name="num2[{$smarty.section.ill.index}]" /></td></tr>
<tr><td>Total:</td><td><input type="text" name="total[{$smarty.section.ill.index}]"onBlur = "mytest()" /></td></tr>
</table>
{/section}
And here's the javascript:
function mytest()
{
for (j = 0; j <= customer; j++)
{
var number1= document.getElementsByName("num1[]")[j].value;
var number2 = document.getElementsByName("num2[]")[j].value;
number1 = Number(number1);
number2 = Number(number2);
var result = number1 + number2;
document.getElementsByName("total[]")[j].value = result;
}
}
Thank you for your help,
~alyssa
--
Smarty General Mailing List (http://smarty.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php