By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,299 Members | 1,415 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,299 IT Pros & Developers. It's quick & easy.

Referencing dynamic forms with Javascript events

P: n/a
On my website (www.cooljools.biz), I have a list of products which are
displayed using PHP and a MySQL database (this tech detail is probably
irrelevent to the problem). Next to each item I have an 'Add' button
allowing customers to add the item to the shopping cart.

I need some way to toggle the text on the button between 'Add' and
'Added'. The problem being there is no way to know how many products
there will be, and therefore naming all the buttons uniquely would be
difficult.

I was wondering if there was a way of programatically finding out
which button fired the event and then do something along the lines of:

if (cause.value == "Added") {
cause.value == "Add";
}
else cause.value == "Added";

Any help on this would be appreciated.

Jacqueline
Jul 20 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
VK
<input type="button" value="add" onClick="update(this, this.value);">

....
function update(clickedButton,currentLabel) {
clickedButton.value = (currentLabel == 'Add') ? 'Remove' : 'Add';
}
....

Jacqueline <ja*******@hotmail.com> wrote in message
news:c5**************************@posting.google.c om...
On my website (www.cooljools.biz), I have a list of products which are
displayed using PHP and a MySQL database (this tech detail is probably
irrelevent to the problem). Next to each item I have an 'Add' button
allowing customers to add the item to the shopping cart.

I need some way to toggle the text on the button between 'Add' and
'Added'. The problem being there is no way to know how many products
there will be, and therefore naming all the buttons uniquely would be
difficult.

I was wondering if there was a way of programatically finding out
which button fired the event and then do something along the lines of:

if (cause.value == "Added") {
cause.value == "Add";
}
else cause.value == "Added";

Any help on this would be appreciated.

Jacqueline

Jul 20 '05 #2

P: n/a
Thank you - it does everything I wanted (and is so simple, I cannot
belive I spent ages over this!!)
Jul 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.