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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T07:19:53+00:00 2026-06-04T07:19:53+00:00

I am trying to right some some JavaScript to define a variable using PHP.

  • 0

I am trying to right some some JavaScript to define a variable using PHP. The variable has a little jQuery in it which should get rendered by the client. I say “should” but really mean I want it to. What should I do to make o2 the same as o1 (i.e. covert the jQuery)?

Thank you!

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1" /> 
<title></title> 
<script src="http://code.jquery.com/jquery-latest.js" type="text/javascript"></script> 
<script>
$(function() {
    var o1={"foo":{"bar": "abc/index.php?="+$("#id").val()}};
    console.log(o1);
<?php
$d='abc/index.php';
$json='{"foo":{"bar": "'.$d.'?id=\"+$(\"#id\").val()"}}';
//echo($json);
$json=json_decode($json);
//echo(print_r($json,1));
$json=json_encode($json);
//echo($json);

echo("var o2=".$json.";");
?>

console.log(o2);
});

</script>

</head>

<body>
<input type="hidden" id="id" value="123" />
</body> 
</html> 
  • 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-04T07:19:54+00:00Added an answer on June 4, 2026 at 7:19 am

    You have this:

    <input type="hidden" id="id" value="123" />
    

    So I can assume that you are getting that id from a db right? Maybe like this:

    <input type="hidden" id="id" value="<?php echo $row[id];?>" />
    

    If this is the case do the following (I tested and works):

    You don’t need hidden inputs to do it.

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
    <html xmlns="http://www.w3.org/1999/xhtml"> 
    <head> 
    <meta http-equiv="content-type" content="text/html; charset=ISO-8859-1" /> 
    <title></title> 
    <script src="http://code.jquery.com/jquery-latest.js" type="text/javascript"></script> 
    <script>
    $(function() {
    
        <?php
            //From your SQL query you obtained
            //$row['id'] = 123;
            $id = $row['id'];
        ?>
    
        var o1={"foo":{"bar": "abc/index.php?=" + <?php echo $id ?>}};
        console.log(o1);
    
        <?php
        $d='abc/index.php';
        $json='{"foo":{"bar": "'.$d.'?='.$id.'"}}';
        //echo($json);
        $json=json_decode($json);
        //echo(print_r($json,1));
        $json=json_encode($json);
        //echo($json);
        echo("var o2=".$json.';');
        ?>
    
        console.log(o2);
    });
    </script>
    </head>
    <body>
    </body> 
    </html>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to do a build using steal/buildjs of Javascript MVC, which should
Im trying to get this working but for some reason it's just not right.
I am trying to echo out some JavaScript, but I can't get the formatting
I've been trying to use http://livepipe.net/control/tabs to get some javascript tabs up and running
I'm trying to learn some javascript and have gotten stuck. Right now, I have
I am trying to right align some text in a javascript alert box. It
I am trying to right-align the output of some PL/SQL code, but dbms_output.put_line is
Right now, what i'm trying to do is display some lists on a page
I am trying to setup a form that takes in some song information. Right
Right now I'm trying desperately to get @font-face to work in my website. This

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.