| | #1 |
| Membership Site, SEO Guy War Room Member Join Date: 2010 Location: Bangkok, Thailand
Posts: 697
Thanks: 198
Thanked 258 Times in 165 Posts
Blog Entries: 1 |
Hi All, I'm attempting to put several instances of Javascript code on the same page but it isn't working. Here is the code that goes in the header... Code: <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.");
}
cbrblaccpt
</script> Code: <p align="center"><form action="#"><input type="checkbox" onchange="toggleAccept()" id="agreeCheckbox">
<label for="agreeCheckbox"><b>I understand that this product is billed on a monthly basis and that I can cancel my subscription at any time.</b></label></form></p>
<p align="center"><a href="http://2-monthly.vicdorfman.pay.clickbank.net/?cbur=a" id="accept" onclick="mustAccept(); return false;"><img alt="" src="images/signup-37.jpg" style="border: 0px solid ; width: 350px; height: 147px;" /></a></p> Please help! Thanks, Vic |
| | |
| |
| | #2 |
| Coder of the Web War Room Member Join Date: 2010 Location: Kansas City, MO - United States
Posts: 75
Thanks: 2
Thanked 40 Times in 9 Posts
| HTML Code: var acceptLink = document.getElementById("accept");
var agreeCheckbox = document.getElementById("agreeCheckbox"); If you keep the same id's then it will only work on the first items with those id's. Try changing the id's for the 2nd and 3rd items you are trying to make calls on and see if that fixes the issue. Dave |
|
Tired of fighting with WordPress to build the site you want? You shouldn't have to spend hours tweaking your website to bend to your will. Take the next step in your journey to WordPress mastery with wordpress4anyone.com | |
| |
| | #4 |
| Active Warrior Join Date: 2014 Location: UK [North Yorkshire]
Posts: 59
Thanks: 0
Thanked 9 Times in 9 Posts
|
Can you post a link to the page that your having problems with or more of the html. Like dwbiz05 said it sounds like your element ids aren't unique.
|
| | |
| |
|
| Bookmarks |
| Tags |
| add, instances, javascript, multiple, page |
| |