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

  • Home
  • SEARCH
  • 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 6242351
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T11:56:21+00:00 2026-05-24T11:56:21+00:00

I recently learned that when using onclick, for a button, the field name and

  • 0

I recently learned that when using onclick, for a button, the field name and button id have to each be unique. While thats not a problem, depending on how many rows my script outputs, this could be a lot of waste.

For example, i have a while loop, it does this for each person on my server (minecraft), so it could be 10, it could be 50.

this is the code to create the js objects

  $kickbtn .= "    $('#kick_btn$k').click(function(event) { 
    var player_name$k = jQuery('input[name=\"player$k\"]').val()
    jQuery.get('testing.php?action=kick', { player_input: player_name$k} );
    alert('Successfully kicked');
  });\n\n";

this is the form data

    <form name=\"$pdata[name]\" action=\"\">
      <input type=\"hidden\" name=\"player$k\" value=\"$pdata[name]\">
      <input type=\"submit\" id=\"kick_btn$k\" value=\"Kick Player\">
    </form>
  $k++;

Is there an easier way to accomplish this without creating all this excess code?

The output is nice in the html, and it does work, just hoping theres something a little more dynamic i can do, and not so messy in the code. Below is from the parsed code and works and looks good.

$('#kick_btn14').click(function(event) { 

    var player_name14 = jQuery('input[name="player14"]').val()

    jQuery.get('testing.php?action=kick', { player_input: player_name14} );

    alert('Successfully kicked');

  });
  • 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-05-24T11:56:22+00:00Added an answer on May 24, 2026 at 11:56 am

    Only one delegated event handler is needed, which means attaching it to a parent/container element, unless you want 50+ click handlers in your document which will unnecessarily slow things down:

    // bind to all elements starting with 'kick_btn' within #container
    // (could even be 'body')
    $("#container").delegate('[id^="kick_btn"]', "click", function(event) {
    
        // get the current player number from the id of the clicked button
        var num = this.id.replace("kick_btn", "");
        var player_name = jQuery('input[name="player' + num + '"]').val();
        jQuery.get('testing.php?action=kick', {
            player_input: player_name + num
        });
        alert('Successfully kicked');
    });
    

    Reference:

    • http://api.jquery.com/attribute-starts-with-selector/
    • http://api.jquery.com/delegate/
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have recently learned that sql server 2005 does not support UTF8: UTF8 problem
Possible Duplicate: Using A* to solve Travelling Salesman Problem I have recently learned that
I recently learned that all stl containers have swap function: i.e. c1.swap(c2); will lead
Recently I've learned that setting the charset using the meta tag is a pretty
I've recently learned that python doesn't have the switch/case statement. I've been reading about
From an old answer I have recently learned that Google Analytics, besides the traditional
I learned about Lazy class in .Net recently and have been probably over-using it.
I have recently learned that there are bugs in JDK7 for hotspot compiler optimization.
I have recently learned that if you have a reference to a class as
I have recently learned that you can use a neat switch statement with fallthrough

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.