Click to See Complete Forum and Search --> : Can't figure it for the life of me.


finkelman
04-02-2003, 06:31 AM
Hello,

I usually don't like to ask before I do the research but here I spent 2 days online trying to find an answer that I'm sure is right in front of my nose.

I have the following problem.

I am using a ASP page to generate the listing of products found. I have a "Add To Cart" button next to each listing in each row found. Right next to the button, I have a quantity field which allows to customer to enter how many do they want of the particular product. The way I am updating the shopping cart is using layers, so the page doesn't actually reload as it just updates the page on the layer. I named the HTML quantity field the name of the product id since I need to tell the javascript what field to use in order to see the quantity entered for the product being added. My problem is that it just doesn't want to pick up that field. Let me show you what I'm doing and maybe it will make a little more sense.


This is the HTML portion of the code that allows the customer to add to the shopping cart. Note that the value (461) is dynamic and changes based on the the results of the ASP page. This is just an example.

<input type="text" value="1" name="461" size="1" maxlength="50">&nbsp;<a href="javascript:addToCart('461');"><img border="0" src="./images/new/addtocart.gif"></a>

The follwing is the JavaScript portion of the code.

<script language="javascript">

function addToCart(item)
{
surl = 'cart_action.asp?add=1&item_id='+item+'&qty=' + document[item.value];
content.document.location.replace(surl);
}
</script>

As you can see, I need to pass the quantity field to the cart_action.asp page as well. For some reason it is not passing that field plus it gives me error messages.

What am I doing wrong?

Thanks in advance for your help.

gil davis
04-02-2003, 06:43 AM
Originally posted by finkelman
surl = 'cart_action.asp?add=1&item_id='+item+'&qty=' + document[item.value];Probably should besurl = 'cart_action.asp?add=1&item_id='+item+'&qty=' + document.formName[item].value;where formName is the name of your form.

finkelman
04-02-2003, 06:59 AM
Hi,

Thanks for the super fast response. I have named the form "Add" and tried to do as you said "document.Add[item].value" but it still does not work. I don't if the JavaScript format I am using is correct. Do you know?

Thanks Again.

gil davis
04-02-2003, 07:41 AM
Without the whole page, it would be hard to tell. However, according to W3C, object names cannot start with a number. Perhaps that is your problem.

Alerts work great for debugging. What does "surl" contain after the statement?