Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Having An HTML Checkbox Call A JavaScript Function

Posted on 2013-06-25
2
943 Views
Last Modified: 2013-11-19
ClickBank requires for recur bill products to have a checkbox that the value is sent to the ClickBank payment processing that indicates whether the customer accepted (checked) or declined (not checked) the billing agreement.  ClickBank gives the following code as an example:

<script type="text/javascript">
function toggleAccept() {
var acceptLink = document.getElementById("accept");
var agreeCheckbox = document.getElementById("agreeCheckbox");
if (agreeCheckbox.checked) {
acceptLink.onclick=function() {
window.location=this.href + "&cbrblaccpt=true";
return false;
}
} else {
acceptLink.onclick=function() {
mustAccept();
return false;
}
}
}
function mustAccept() {
window.alert("By clicking accept, you agree to the payment terms of this recurring product.");
}

cbrblaccptl

</script>

My HTML/JavaScript is a bit rusty.  How would I set up the checkbox in HTML to call the above code?

Thanks,
0
Comment
Question by:techhound
2 Comments
 
LVL 18

Accepted Solution

by:
zc2 earned 500 total points
ID: 39275816
So, you need the "Accept" link and the "Agree" checkbox, something like these:

<input type="checkbox" id="agreeCheckbox" onclick="toggleAccept()">
<label for="agreeCheckbox">Check if you accept the billing agreement then click the link below.</label>
<br/>
<a  id="accept" value="Accept" onclick="mustAccept()"
href="http://www.bankURL.com/path/blah-blah?otherpar=1234">Accept</a>

Open in new window

By default, the link has the "mustAccept()" onclick handler (which shows the alert message).
The checkbox has the toggleAccept() onclick event handler, calling the function from the sample.
When the user clicks the checkbox the code toggles the link's onclick handler to the function which appends the extra parameter to the link's URL. So, after that the user has to click on the link and the combined URL will be navigated to.
0
 

Author Closing Comment

by:techhound
ID: 39275845
Very timely and did exactly what I needed.
Thanks
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
forgetful about js objects 8 46
xjs: how to get sum of value in for loop 2 18
How can I make the first part identical to the second ? 1 26
Selected in an option list 13 20
Because your company can’t afford for you to make SEO mistakes, you’ll want to ensure you’re taking the right steps each and every time you post a new piece of content. This list of optimization do’s and don’ts can help you become an SEO wizard.
FAQ pages provide a simple way for you to supply and for customers to find answers to the most common questions about your company. Here are six reasons why your company website should have a FAQ page
Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question