www.webdeveloper.com
Results 1 to 4 of 4

Thread: 🔴► How to execute javescript by clicking a html image? (sorry total noob to JS)

  1. #1
    Join Date
    Feb 2012
    Posts
    23

    🔴► How to execute javescript by clicking a html image? (sorry total noob to JS)

    I need to open a shopping cart by clicking on a button/image on my website.

    This is the jave code for the shopping cart:
    Code:

    Code:
    <script>
        paypal.minicart.view.show();
    </script>
    How do I link that to a HTML image?

  2. #2
    Join Date
    May 2006
    Location
    Somewhere behind your screen
    Posts
    1,674
    Code:
    <img src="your_image_src" onclick="myfunc()" />
    <script>
    function myfunc(){
        paypal.minicart.view.show();
    }
    </script>

  3. #3
    Join Date
    Feb 2012
    Posts
    23
    I tried this and it did not work :-(

  4. #4
    Join Date
    May 2006
    Location
    Somewhere behind your screen
    Posts
    1,674
    really? try this one:

    Code:
    <!doctype html>
    <html>
    <head>
    <meta charset="utf-8" />
    <title>123</title>
    <style>
    body{text-align:center;padding-top:300px;}
    </style>
    <script>
    function $(id){return document.getElementById(id);}
    
    var paypal={
    minicart:{
    view:{
    show:function(){
    document.body.style.paddingTop='10px';
    $('p_m_v_s').innerHTML='<h1>Just because</h1><img height="500" src="http://www.aceshowbiz.com/images/wennpic/chuck-norris-premiere-the-expendables-2-01.jpg" alt="" />';
    $('p_m_v_s').firstChild.scrollIntoView(true);
    }
    }
    }
    };
    </script>
    </head>
    <body>
    <div id="p_m_v_s">
    <img src="http://i599.photobucket.com/albums/tt72/dutchsamurai/chucknorris3.png" alt="just because" onclick="paypal.minicart.view.show()" />
    <br />
    <b>click da pic</b>
    </div>
    </body>
    </html>

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles