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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:45:00+00:00 2026-05-26T09:45:00+00:00

Im new to php, I dont have good idea how to make things between

  • 0

Im new to php, I dont have good idea how to make things between php and javascript please correct me If im wrong

<!doctype html>
<html>
<head>
<Script type="text/javascript">
function show(m)
{
 var k = document.getElementById(m);
 k.src="four.jpg";
}
</head>
<body>
<? --some php code--
  $i       = 2;
  $row[$i] = "somefilename";
  printf('<img src="%s" id="%d"  onclick="show($i)"/>', $row[$i],$i);
?>

This is my sample.php file.I wanted to raise a onclick event for the image tag through javascript,The img tag is created using php script and I want it to be like these

onclick="show($i)" should be made like below
onclick="show('2')" <!-- and here 2 is the value of php variable

I had tried these way

 onclick="show('$i')" but it passes $i as the parameter to javascript show() function 
 but not the value 2

Please help me with these. actually is it possible ? As i know javascript is a browser scripting and php is server side scripting and can we pass variables from php to javascript these way ?

  • 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-26T09:45:01+00:00Added an answer on May 26, 2026 at 9:45 am

    Funny, everybody who’s answered so far has changed the printf parameter to either use double quotes or concatenate the variable. Why not:

    printf('<img src="%s" id="%d"  onclick="show(%d)"/>', $row[$i],$i,$i);
    

    as he is already using printf()…?

    Furthermore, you don’t actually need the value from PHP as it is already in the HTML. You can just use:

    printf('<img src="%s" id="%d"  onclick="show(this.id)"/>', $row[$i],$i);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am pretty new to php, but I am learning! I have a simple
I'm new to PHP and have installed on Linux to boot (also a newbie).
Has anyone ever modified the post-new.php file in their WordPress installation? I want to
To put it simply i am a fairly new PHP coder and i was
We are in the startup build phase of a new PHP webapp that will
Rather new to php, so sorry if this seems stupid. I'm really copying a
Im new to PHP and I can't figure out what the rules are for
I'm new to PHP and I'm confused seeing some examples calling a function with
I am new to PHP and trying to get the following code to work:
I'm painfully new to PHP, and was trying to set up phpBB on my

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.