Sruthi
Sruthi

Reputation: 479

how to call a jquery function on image click

I've an image in my JSP page. I need to call the jquery function on click of that image. Please help me !!

JSP page look like,

<html>
    <body>
        <input type="image" id="closeAuction" value="Close Auction" align="right" src="images/close_auction.png" onclick="return endAuction();" disabled / > 
    </body>
</html>

My jquery function inside the script tag looks like,

<script src="JS/jquery-1.3.2.min.js">
    $(document).ready(function() {     
        $('#closeAuction').click(function() {
            location.reload();     
        });    
    });
</script>

But the script doesn't work!! Could anyone help on calling a function on image click..

Upvotes: 1

Views: 30995

Answers (4)

Gabriele Petrioli
Gabriele Petrioli

Reputation: 195992

You cannot put code inside a script tag that is used to load an external resource.

<script src="JS/jquery-1.3.2.min.js"></script>
<script>
$(document).ready(function() {     
    $('#closeAuction').click(function() {
        location.reload();     
    });    
});
</script>

Upvotes: 0

Sridhar Narasimhan
Sridhar Narasimhan

Reputation: 2653

Replace $('#closeAuction) with $('#closeAuction')

Thanks

Upvotes: 1

Selvakumar Arumugam
Selvakumar Arumugam

Reputation: 79830

You are missing a quote.. $('#closeAuction')

Change $('#closeAuction) to $('#closeAuction')

Also you need to put it in a new script

<script src="JS/jquery-1.3.2.min.js"></script>
<script type="text/javascript"> //Added new `<script>` tag
   $(document).ready(function() {
     //added missing-v quotes 
     $('#closeAuction').click(function() {
        location.reload();     
     });    
   });    
</script>

Upvotes: 5

Rory McCrossan
Rory McCrossan

Reputation: 337560

You're missing a closing quote and you also need to place your code in it's own script block. Try this:

<script src="JS/jquery-1.3.2.min.js"></script>
<script type="text/javascript">
    $(document).ready(function() {     
        $('#closeAuction').click(function() { // <-- note closing quote on selector.
            location.reload();     
        });    
    });
</script>

Is there a specific reason you're using such an outdated version of jQuery? You should try upgrading to 1.8.3.

Upvotes: 3

Related Questions