Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9321677
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T03:54:09+00:00 2026-06-19T03:54:09+00:00

I am having some trouble trying to call a JQuery function from multiple images

  • 0

I am having some trouble trying to call a JQuery function from multiple images on my page. if someone could help me out that would be great.

This is my code:

HTML

        <input type="image" name="rateButton[1]" src="img/Rate1.png" height="40" width="40" value="1" onclick="rateBox(1)"/>
        <input type="image" name="rateButton[2]" src="img/Rate2.png" height="40" width="40" value="1" onclick="rateBox(2)"/>
        <input type="image" name="rateButton[3]" src="img/Rate3.png" height="40" width="40" value="1" onclick="rateBox(3)"/>
        <input type="image" name="rateButton[4]" src="img/Rate4.png" height="40" width="40" value="1" onclick="rateBox(4)"/>
        <input type="image" name="rateButton[5]" src="img/Rate5.png"  height="40" width="40" value="1" onclick="rateBox(5)"/>
        <input type="image" name="rateButton[6]" src="img/Rate6.png" height="40" width="40" value="1" onclick="rateBox(6)"/>
        <input type="image" name="rateButton[7]" src="img/Rate7.png" height="40" width="40" value="1" onclick="rateBox(7)"/>
        <input type="image" name="rateButton[8]" src="img/Rate8.png" height="40" width="40" value="1" onclick="rateBox(8)"/>
        <input type="image" name="rateButton[9]" src="img/Rate9.png"  height="40" width="40" value="1" onclick="rateBox(9)"/>
        <input type="image" name="rateButton[10]" src="img/Rate10.png" height="40" width="40" value="1" onclick="rateBox(10)"/><br>

JQuery

$(document).ready(function(){
    function rateBox(rating){
        // Ajax Call here...
    }
});
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-19T03:54:10+00:00Added an answer on June 19, 2026 at 3:54 am

    You should move your function outside the .ready() function as others have suggested.

    Also the best practice for attaching events to multiple elements is to delegate the event to the parent element. It will attach only one event and listen for events that bubble-up from the selector used. Ex. using JQuery…

    $(parent-container).on('click', element-selector, function(e){
      // Ajax call here.
    });
    

    In your situation you can add a parent wrapper (with id = “ratings”) and add a class to your rateButtons (class = “rateButton”)

    reduced DOM for the sake of clarity.

    <div id="ratings">
        <input type="image" class="rateButton" name="rateButton[1]" src="img/Rate1.png" height="40" width="40" value="1"/>
        <input type="image" class="rateButton" name="rateButton[2]" src="img/Rate2.png" height="40" width="40" value="1"/>
        <input type="image" class="rateButton" name="rateButton[3]" src="img/Rate3.png" height="40" width="40" value="1"/>
        <input type="image" class="rateButton" name="rateButton[4]" src="img/Rate4.png" height="40" width="40" value="1"/>
        <input type="image" class="rateButton" name="rateButton[5]" src="img/Rate5.png"  height="40" width="40" value="1"/>
    </div>
    <br>
    

    and then bind the event on parent (outside the ready function of-course)

    $('#ratings').on('click', '.rateButton', function(e){
       /* alternatively if the additional parent element is not desired  
          the event can be delegated to the document */
    
       var elem = this; // to refer to the clicked object
       var index = $(this).index(); // to get the index, this index is 0 based
       alert('clicked element index: '+index);
       // Ajax call here.
    });
    

    Example

    JQuery .on() documentaion

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having some trouble trying to figure out, how to accomplish the following.
I'm having some trouble trying running a function only once when onresize event is
I am having some trouble trying to figure out how to parse information collected
I am having some trouble trying to print from a file. Any ideas? Thanks
I am having real trouble trying to deserialize some XML and was hoping someone
I am having some trouble pulling multiple custom post types from a Custom Wordpress
I'm having some trouble trying to develop a regular expression which will pick out
I'm trying to learn some Erlang and having trouble figuring out the best approach
I've been having some trouble trying to send a file from a server to
I'm having some trouble trying to incorporate a read and write statement into evaluateStatementInner

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.