Solved

Having An HTML Checkbox Call A JavaScript Function

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

Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
In this tutorial viewers will learn how to embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…
The viewer will learn how to dynamically set the form action using jQuery.

930 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now