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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T05:37:03+00:00 2026-06-05T05:37:03+00:00

Possible Duplicate: How to pass a PHP variable to Javascript? I need to somehow

  • 0

Possible Duplicate:
How to pass a PHP variable to Javascript?

I need to somehow make this function to accept parameter.

index.html

function dataOut(name2) {
    var names = name2.value;
    document.getElementById("output2").innerHTML = names;
    //even document.getElementById("output2").innerHTML= "blablabla"; 
    //just to show that it works
}

And the function will be called from :

dbase.php

...
echo "<td><a href='javascript:dataOut(this.value)'>" . $row['FirstName'] . "</a></td>";
...

I dont have problem on displaying the the table. The link does show with their respective "$row[‘FirstName’]" which are string from database. I tried to use non-parameter function:

function dataOut(){}
echo "<td><a href='javascript:dataOut()'>" . $row['FirstName'] . "</a></td>";

and these work fine.

If i try to pass parameter, the function will not do anything; not even if i just want to print random string as in the commented section of the function. If i hover my mouse on the link created within that table i see:

javascript:dataOut(firstname)
//where first name is the value of the $row['FirstName']

Alternatives that i tried:

echo "<td><a href='javascript:dataOut(this.value)'>" . $row['FirstName'] . "</a></td>";
echo "<td><a href='javascript:dataOut($row['FirstName'])'>" . $row['FirstName'] . "</a></td>";
echo "<td><a href='javascript:dataOut('" . $row['FirstName'] .'")'>" . $row['FirstName'] . "</a></td>"; //this give me undefined variable error
echo "<td><a href='javascript:dataOut(". $row['FirstName']. ")'>" . $row['FirstName'] . "</a></td>"; // this no error

Any help would be appreciated. More over i tried also <a onclick=dataOut ....> which doesnt work either.

  • 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-05T05:37:04+00:00Added an answer on June 5, 2026 at 5:37 am

    You shouldn’t try to create JavaScript strings by concatenating quotes and plain strings. Use json_encode() instead which is guaranteed to output a valid JavaScript expression:

    echo "<td><a href='javascript:dataOut(".json_encode($row['FirstName']).")'>" . $row['FirstName'] . "</a></td>";
    

    On a side-note, using javascript: urls is generally a bad idea. Better use onclick="dataOut(...); return false;" instead and use a useful href value or # if no proper URL for people without JavaScript exists. Of course it would be even better to register the event properly instead of using an inline event, and storing the data in a data- attribute but this would be even more off-topic here.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Pass a PHP string to a Javascript variable (and escape newlines) I'm
Possible Duplicate: Pass a PHP string to a Javascript variable (including escaping newlines) So
Possible Duplicate: How to pass a variable / data from javascript to php and
Possible Duplicate: How to pass text in a textbox to javascript function? I need
Possible Duplicate: What's the best way to pass a PHP variable to Javascript? I
Possible Duplicate: Pass a PHP string to a Javascript variable (and escape newlines) I
Possible Duplicate: Pass a PHP string to a Javascript variable (including escaping newlines) Hy,
Possible Duplicate: pass parameter in g:remoteLink as result of javascript function I am trying
Possible Duplicate: How do you pass a function as a parameter in C? Is
Possible Duplicate: How to call a JavaScript function from PHP? I have a php

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.