Referencing dynamic forms with Javascript events

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jacqueline

    #1

    Referencing dynamic forms with Javascript events

    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
  • VK

    #2
    Re: Referencing dynamic forms with Javascript events

    <input type="button" value="add" onClick="update (this, this.value);">

    ....
    function update(clickedB utton,currentLa bel) {
    clickedButton.v alue = (currentLabel == 'Add') ? 'Remove' : 'Add';
    }
    ....

    Jacqueline <jacqui932@hotm ail.com> wrote in message
    news:c58619d6.0 309230837.48094 fd1@posting.goo gle.com...[color=blue]
    > 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[/color]


    Comment

    • Jacqueline

      #3
      Re: Referencing dynamic forms with Javascript events

      Thank you - it does everything I wanted (and is so simple, I cannot
      belive I spent ages over this!!)

      Comment

      Working...