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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T18:16:40+00:00 2026-06-07T18:16:40+00:00

Possible Duplicate: passing variables from php to javascript I’m dynamically generating a list. I

  • 0

Possible Duplicate:
passing variables from php to javascript

I’m dynamically generating a list. I want to make each row hover on mouseover and clickable to a link. I want the link to pass the id of the content of the row.

Basically:

foreach ($courses as $cid=>cinfo){ 
  $univ = $cinfo['univ'];
  $desc = $cinfo['desc'];
  $size = $cinfo['size'];
  $start = $cinfo['start'];
  print "<div class='rc_desc' id='rc_desc$cid'>"."$desc<br/>"."<b>$univ</b><br/>".
        "<span>Number of students</span>: $size<br/>".
        "<span>Started at</span>: ".date('F d, Y',strtotime($start))."<br/>".
}

<script>
    $(function ()
    {
      $('#rc_desc$cid').hover(function ()
      {
        $(this).toggleClass('.tr');
      });
      $('#rc_desc$cid').click(function ()
      {
        $(location).attr('href','student.php?$cid');
      });
    });
  </script>

The issue is in the js/jquery. I want to be able to grab the $cid and pass it to the student.php page upon click. The php code above works but the js won’t of course. I know the fundamental of client-side vs server-side languages. This question doesn’t warrant a lecture. I know I cannot do this exactly, but it is what I want to happen ultimately. Any thoughts on how I can achieve this simply? Thanks in advance my friends!

  • 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-07T18:16:42+00:00Added an answer on June 7, 2026 at 6:16 pm

    Yes, if you include the <script> section in your PHP code, you can do something similar to the following:

    <script>
        var foo = <?php echo $foo; ?>;
    </script>
    

    In your case, you would be looking into the following code structure:

    <script>
        $(function () {
            $('#rc_desc<?php echo $cid ?>').hover(function () {
                $(this).toggleClass('.tr');
            });
            $('#rc_desc<?php echo $cid ?>').click(function () {
                $(location).attr('href', 'student.php?<?php echo $cid ?>');
            });
        });
    </script>
    

    The reason why this is possible is because although the Javascript is run on the client-side, it’s processed on the server-side first prior to being presented on the page. Thus, it’ll replace all necessary instances of $cid with the one you have included.

    Enjoy and good luck!

    EDIT:

    <script>
        $(function () {
            $('.rc_desc').hover(function () {
                $(this).toggleClass('.tr ');
            });
            $('.rc_desc').click(function () {
                $(location).attr('href', 'student.php?' + $(this).attr('id').split('rc_desc')[1]);
            });
        });
    </script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Passing multiple parameter to PHP from Javascript I am currently trying to
Possible Duplicate: C++ passing variables in from one Function to the Next. The Program
Possible Duplicate: Passing javascript variable to PHP Hi I wonder if it's possible to
Possible Duplicate: passing value to JSP via javaScript i want to pass value of
Possible Duplicate: What is the safest way of passing arguments from server-side PHP to
Possible Duplicate: Passing JavaScript Array To PHP Through JQuery $.ajax I'm trying to pass
Possible Duplicate: Passing only two variables between controller and view - best practice? There
Possible Duplicate: How do I make a request using HTTP basic authentication with PHP
Possible Duplicate: In PHP (>= 5.0), is passing by reference faster? Say I'm dealing
Possible Duplicate: PHP passing parameters via URL I know that if you have a

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.