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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T15:42:23+00:00 2026-06-09T15:42:23+00:00

I have a requirement to get a variable from PHP to Javascript when clicked

  • 0

I have a requirement to get a variable from PHP to Javascript when clicked by the user. I have an array of data returned by a query and I need to pass an ID value for the element clicked so that I can populate an additional data set via the .load using another PHP page. I am unsure how todo this?

Javascript Code in Page:

<script type="text/javascript"> 
$(function () { 
 $("#pass_userid_div").click(function () {
    
    $("#another_div").load('remote_pages/get_info.php?userid=' + $GET_THE_USERID_AND_PASS_HERE);
  });
});
</script> 

PHP Code in Page:

$query_str = "SELECT id, username, dateregistered FROM users";
$query = mysql_query($query_string) or die(mysql_error());

while ($results = mysql_fetch_array($query)) {
    print "<div id='pass_userid_div'>{$results['username']}</div>";
    print "<div>{$results['dateregistered']}</div>";
}
  • 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-09T15:42:24+00:00Added an answer on June 9, 2026 at 3:42 pm

    Why must it be a div? Use an interactive element:

    PHP:

    while ($results = mysql_fetch_array($query)) {
        print "<button type='button' name='pass_userid_div' value='{$results['id']}'>{$results['username']}</button>";
        print "<div>{$results['dateregistered']}</div>";
    }
    

    JavaScript:

    <script type="text/javascript"> 
    $(function () { 
     $("button[name='pass_userid_div']").click(function () {
        $("#another_div").load('remote_pages/get_info.php?userid=' + $(this).val());
      });
    });
    </script> 
    

    Update: If it really must be a div, use a data- attribute:

    <div class="pass_userid_div" data-userid='{$results['id']}'…
    
    …$(this).data("userid")
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a requirement in a shell script. I get this location information from
I'm trying to get data from a database if a link is clicked. Basically
We need to get data out of an older accounting system. We have received
I have requirement to get Facebook friends list with their images. How can I
i am using gwt with jdo datanucleus. i have requirement to get child with
I have a requirement that i want to get all the system services running
I have the following MySQL query: SELECT title, description FROM some_table WHERE MATCH (title,description)
I have a simple requirement, but can't get the SELECT statement right, so that
I have made a custom ajax script to parse the JSON returned from the
I have been playing with XML and PHP, I have googled to get the

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.