Register Advertise with usHelp Desk Today's Posts Search

Closed Thread
Thread Tools Search this Thread
Unread 18th Apr 2013, 11:20 AM   #1
Advanced Warrior
War Room Member
 
rimam1's Avatar
 
Join Date: 2009
Location: Chicago
Posts: 532
Thanks: 159
Thanked 153 Times in 54 Posts
Default
How Do I Use a Button to Trigger JavaScript?
Share on: 
fb share twitter share gplus share more share

Hey guys,

I am using an OptimizePress "Add to Cart" button. I want it to trigger this javascript code:

<a href="http://gum.co/sogr">The Science of Getting Ripped_draft</a><script type="text/javascript" src="https://gumroad.com/js/gumroad.js"></script>

When I add that to my page, I see the vendor provided "add to cart" button, but I want that code to trigger my OptimizePress "Add to Cart" button.

If you go to www.TheScienceofGettingRipped.com/guide you'll see what I mean. Currently, if you click the "Add to Cart" button, it redirects you to another site. However, if you click the vendor provided button, it triggers the javascript overlay.

How can I use my button with their javascript overlay?

Thanks in advance!

Raza
rimam1 is offline  
Unread 18th Apr 2013, 12:02 PM   #2
Advanced Warrior
War Room Member
 
Brandon Tanner's Avatar
 
Join Date: 2006
Location: USA
Posts: 1,907
Thanks: 236
Thanked 1,377 Times in 676 Posts
Default
Re: How Do I Use a Button to Trigger JavaScript?
Share on: 
fb share twitter share gplus share more share

I'm not real clear on exactly what you're trying to accomplish here, but if you simply want a button click to trigger an external Javascript file, then you can do this (jQuery)...

Code:
<script type="text/javascript">
$(document).ready(function(){
  $("#myButton").click(function(){
    $.getScript("full/path/to/js/file.js");
  });
});
</script>
^ The above example assumes that your button has the ID "myButton". And you'll need to change the path to the real path of your js file.


Brandon Tanner is offline  
Closed Thread


Bookmarks

Tags
button, javascript, trigger


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




All times are GMT -6. The time now is 07:27 AM.