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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T06:19:39+00:00 2026-05-25T06:19:39+00:00

I have some PHP code which runs a loop, spitting out a button and

  • 0

I have some PHP code which runs a loop, spitting out a button and a span, each time it loops, like this:

(inside loop)

echo "<span id=\"sendbutton\"> <input type=\"button\" event='$eventID' id=\"sendsomeone\" value=\"Send a family member\"/> </span>";
echo "<span id=\"nameshere\"></span>";

Later in my code, I have jquery that catches one of the button clicks, and does code, then writes back. What I want it to do is to write back to the span immediately following the button that was clicked.

$('#nameshere').append('Hey! this was the button that you clicked!'); 

Clearly, in my example, it does not quite work the way I want. Each loop creates a span with an id of nameshere, and so when I click any of the buttons, it appends to the topmost span. I could easily use $eventID as the span ID, but I don’t know how to accurately reference it in my javascript.

How can I have it append to the button that was clicked? $(this) perhaps? I just don’t know how to use it correctly.

Edit, more info:

My click code looks like this:

$('input:button').click(function() {...}

Even more info:

I should have asked more clearly. I can make my span ID unique. I just set it to be $eventID. Done. But how do I call that from in jquery?

  • 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-25T06:19:40+00:00Added an answer on May 25, 2026 at 6:19 am

    You can’t have elements with duplicate ids. Change your Id’s to classes and try this.

    $("input.sendsomeone").click(
        $(this).next("span").html('Hey! this was the button that you clicked!')
    );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some PHP code which allows me to sort a column into ascending
I have some PHP code which stores whatever is typed in a textbox in
I have some php files in a server which generate xml code in them.
I have some code I've written in PHP for consuming our simple webservice, which
So I have some PHP code that looks like: $message = 'Here is the
I have a string variable which also has some PHP code in it. The
I have some PHP 5.3 code which builds an array to be passed to
Say you have a file myfile.php which executes some PHP code. Could this file
All, I have some PHP PDO code that looks like this: <?php ... $query=$dbh->prepare(SELECT
We have a loop in our PHP code which inserts rows into a table.

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.