Hi,
This is my first post here, so please let me know if I have failed, dispite reading the stickies at the top, to post in an approved manner.
My problem is this; I am working on an ecommerce site which generates the product listings dynamically from SQL databases. On each page, the items listed are looping through the same form to be displayed. Currently, to add an item to the shopping cart, the customer clicks on an <a href><img></a> of a custom button, which activates a javascript function to add the item to the cart. All this works fine. I am trying to add the functionality of being able to add items to the cart when “enter” is keyed. I have a script which detects the enter key with no problem, but it only will submit the last item generated on the page. For example, if there are the items apples, pears, bananas, & grapes listed the fruit category page, when you enter a quantity in any textbox other than the one next to grapes and press enter, you are asked to enter a valid quantity. When entering a quantity next to grapes and pressing enter, x number of grapes are added to the cart.
Here is the code (again, each item display is generated with a loop through this, and more of course):
[code=php]
<script language=”javascript”>
function checkEnter2(e){
var characterCode;
if(e && e.which){
e = e;
characterCode = e.which;
}
else{
e = event;
characterCode = e.keyCode;
}
if(characterCode==13){
preproc(“frmAdd”,”<%=iIndex%>”,”<%=Server.HTMLEncode(Replace(sItemCode,””””,”¶”))%>”,”<%=sItemType%>”,”<%=sEqCode%>”,”0″,”<%=iUnits%>”);
}
else{
return true;
}
}
</script>
<font class = contbold>Qty: </font>
<font class = content><input type=”Text” name=”qty<%=iIndex%>” id=”Qty” value=”<%=iUnits%>” size=”4″ maxlength=”8″ onkeypress=”checkEnter2(event)” class=content>
<%’If iFraction > 1 Then
‘If bAllowSaleUnit = “T” Then Response.Write “Unit(s)” Else
Response.Write sMeasureDesc
‘End if%> <%=sMeasureDesc%></font>
<a href=’javascript:preproc(“frmAdd”,”<%=iIndex%>”,”<%=Server.HTMLEncode(Replace(sItemCode,””””,”¶”))%>”,”<%=sItemType%>”,”<%=sEqCode%>”,”0″,”<%=iUnits%>”)’>
<img ALT=”Buy this item” SRC=”images/Add_To_Cart.gif” BORDER=”0″ VSPACE=”0″ HSPACE=”0″ align=absmiddle></a><br>