Solved

Having An HTML Checkbox Call A JavaScript Function

Posted on 2013-06-25
2
941 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

This article discusses how to create an extensible mechanism for linked drop downs.
Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
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.

777 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