Hi there, wondering if anyone can assist..

I have a form


<cfoutput query = "bagList">
<form name="addToCart" method="post">
<input type="hidden" id="idBg" name="idBg" value="#id_bgs#" />
<input type="button" name="addToCart" value="addToCart" onclick="addToCart();" />

Which passes to my ajax function

// Code

function addToCart() {
var idBg = $F('idBg');
var url ='formAction/addtobag.cfm';
var pars = 'idBg=' + idBg;
var target ='contactSuccess';
var myAjax = new Ajax.Updater(target, url, {method:'get', parameters: pars});

The formAction/addtobag.cfm page updates the cart with the value from the form input "idBg" when the form is submitted..

The issue is that the form is contained in a loop from a coldfusion query, where "value="#id_bgs#"" is the id of the specific bag that needs to be added to the shopping cart. So there is a seperate form generated for each item of merchandise...

At the moment the ajax doesnt seem to be working because no matter what form I click to add an item to the shopping cart, It only adds the item with id=1. I think this is because I need the idBg in my form to be dynamic, but am unsure of how to pass dynamic variables to javascript....
Any ideas? Many thanks