/    Sign up×
Community /Pin to ProfileBookmark

Multiple onClick function in a radio button

Hi everyone,
I have a form with a radio button. Now I want to apply two onClick funtions both will be triggered when the radio is clicked.

Each of the onClick functions are controlled by seperate javascript codes.
The one will open/close some hidden form fields, while the second will add product to shopping cart. Example

  • 1. onclick=”openClose(‘MN’,mainNum,’a1′)”

  • 2. onClick=”addtocart”
  • Someone tell me how to add the two onclick functions in the form feild <input type=”radio” name=”product_selector” onClick=””>

    Someone help.

    to post a comment
    JavaScript

    6 Comments(s)

    Copy linkTweet thisAlerts:
    @CharlesMay 29.2009 — &lt;input type="radio" name="product_selector" onclick="openClose('MN',mainNum,'a1'); addtocart()"&gt;
    Copy linkTweet thisAlerts:
    @MTputer_comMay 29.2009 — If I am not mistaken, the simple solution would be to combine your functions together so that both are called at the same timewith only one function name.
    Copy linkTweet thisAlerts:
    @Y_LessMay 29.2009 — Not really, that can be complicated in terms of combining them and means that the two functions don't exist individually for use elsewhere.
    Copy linkTweet thisAlerts:
    @akluch2authorJun 02.2009 — Hello everyone,

    Thanks for the help.

    This didn't work

    <input type="radio" name="product_selector" onclick="openClose('MN',mainNum,'a1'); addtocart()">

    But i changed the bracket () to {} and placed it just at the end of the first function without the semicolon ; then entered the second function and it worked perfect. Here it is:

    <input type="radio" name="product_selector" onclick="openClose('MN',mainNum,'a1'){} addtocart">

    But i need a little more help. I am trying to do the same thing for two onsubmit functions but its not working. Here is the functions:

  • 1. onsubmit="return AddToCart(this);"

  • 2. onsubmit="return validateFields(this, rules)"


  • These should stay here <Form name="form1" Action="process.php" onsubmit=""

    Any body help.
    Copy linkTweet thisAlerts:
    @CharlesJun 02.2009 — You must have made some other change when you inserted the "{}".onsubmit="return validateFields(this, rules) &amp;&amp; AddToCart(this)"That will only run the second if the first returns true and will only submit the form if both return true--or when the happy user isn't using JavaScript.
    Copy linkTweet thisAlerts:
    @akluch2authorJun 04.2009 — Hi Charles,

    Thanks for your response.

    The code: onsubmit="return validateFields(this, rules) && AddToCart(this)" works great.

    Concerning the onclick function, i guess i didn't give you the correct format of the addtocart function. Here it is:

    onClick="document.order.PRICE.value='100.00'; document.order.NAME.value='Product1'; document.order.ID_NUM.value='11021';"

    The other onclick function is onClick="openClose('MN',mainNum,'a1')"

    The code is:

    <input type="radio" name="product_selector" onclick="document.order.PRICE.value='100.00'; document.order.NAME.value='Product1'; document.order.ID_NUM.value='11021';{} openClose('MN',mainNum,'a1')">
    ×

    Success!

    Help @akluch2 spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 6.17,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @nearjob,
    tipped: article
    amount: 1000 SATS,

    tipper: @meenaratha,
    tipped: article
    amount: 1000 SATS,

    tipper: @meenaratha,
    tipped: article
    amount: 1000 SATS,
    )...