Solved

Having An HTML Checkbox Call A JavaScript Function

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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

706 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

19 Experts available now in Live!

Get 1:1 Help Now