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 9164033
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T14:35:03+00:00 2026-06-17T14:35:03+00:00

I have read a lot about this issue in many threads. The best I

  • 0

I have read a lot about this issue in many threads. The best I have found is
here: jQuery's .click – pass parameters to user function

 // say your selector and click handler looks something like this...
 $("some selector").click({param1: "Hello", param2: "World"}, cool_function);

 // in your function, just grab the event object and go crazy...
 function cool_function(event){
    alert(event.data.param1);
    alert(event.data.param2);
 }

My problem is that I want to assign dynamically values for my parameters. Not just “Hello” etc.

For example I have something like this:

   <?php
   for($i=0;$i<5;$i++){
   ?>
   <input type="text" id="client_<?=$i?>"> 
   <?
   }
  ?>

How can I rewrite jQuery to handle different values for parameters? For example 0,1,2,3,4

Obviously, I can’t do something like

 $("#client_1").click({num:1}, cool_function);
 $("#client_2").click({num:2}, cool_function);
 $("#client_3").click({num:3}, cool_function); 

etc.

  • 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-17T14:35:05+00:00Added an answer on June 17, 2026 at 2:35 pm

    In that specific example, you’re probably best off just grabbing the id, since you’re already outputting it to the element:

    $("some selector").click(function() {
        var num = parseInt(this.id.replace(/\D/g, ""), 10);
        // Do something with `num`
    });
    

    If you weren’t already putting an id there, you could use a data-* attribute:

    <?php
    for($i=0;$i<5;$i++){
    ?>
    <input type="text" data-num="<?=$i?>"> 
    <?
    }
    ?>
    

    …and then retrieve it in the click handler:

    $("some selector").click(function() {
        var num = parseInt($(this).attr("data-num"), 10);
        // Or
        var num = parseInt($(this).data("num"), 10);
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have read a lot about this issue but mine still seems to be
I have read a lot about jquery and i have a simple webservice that
Ok, I have read a lot of posts and resources about this but I
I have read a lot about soft deletes and archive and saw all the
Recently I have read a lot about different NoSQL databases and how they are
I have read a lot of stuff about CI and databases on the blog
I have read about a lot of people having problems with the browser not
I have heard a lot about anti patterns and would like to read a
I have read a lot of topic here and people tend to store IP
I've read about this a lot and I just can't figure it out. It

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.