?
Solved

Having An HTML Checkbox Call A JavaScript Function

Posted on 2013-06-25
2
Medium Priority
?
963 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
[X]
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
2 Comments
 
LVL 18

Accepted Solution

by:
zc2 earned 2000 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

Are You Using the Best Web Development Editor?

The worlds of web hosting and web development are constantly evolving. Every year we see design trends change, coding standards adapt and new frameworks/CMS created. With such a quick pace of change it’s easy to get lost trying to keep up.

See if your editor made the list.

Question has a verified solution.

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

When it comes to write a Context Sensitive Help (an online help that is obtained from a specific point in state of software to provide help with that state) ,  first we need to make the file that contains all topics, which are given exclusive IDs. …
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
In this tutorial viewers will learn how to embed Flash content in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <object> tag to embed Flash content.: To specify that the object is Flash content, d…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

762 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