Hi all,
I am very new to JavaScript, and I am trying to add some functionality for my company’s site. Basically, it’s a shopping cart with up to 10 dynamically generated rows of products. In each row, there’s a text field showing the quantity (with a limit from 0 to 10) for each purchase. My boss wants some graphic up and down arrows that would increment/decrement the value in this box. I successfully managed to achieve this by directly referencing the form field, however, it only worked for one instance, not more. So, I thought of including a simple “line name” in the dynamic code, using it as the field ID and passing it as an argument. For some reason, even though it seems to output line numbers correctly, I get this error:Error: line1 is not defined
Here’s my function:
function fillBox(arg,line) {
if (arg == -1) {
if (document.order.line.value > 0 && document.order.line.value <= 10)
{
i= parseInt (document.order.line.value) + arg;
document.order.line.value=i;
}
}
else {
if (document.order.line.value >= 0 && document.order.line.value < 10)
{
i= parseInt (document.order.line.value) + arg;
document.order.line.value=i;
}
};
}
And here’s what’s passed to it:
a href=”#”><img name=”up” src=”/img/cart/up.gif” width=”20″ height=”20″ border=”0″ onClick=”fillBox(1,<% $line_id %>);”>
(the <% $line_id %> is dynamically generated with Perl and is nothing more than the word “line” plus line number)
Here’s the form field:
<input type=”text” name=”<% $Perl variable for some database content %>” value=”<% $this_item->quantity() %>” size=1 id=”<% $line_id %>”>
I would really appreciate your input, and if any of you are comfortable with both JS and Perl, that would be even better! Thanks!