954,585 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

how to access accessing PHP variable in JavaScript

hi,
iam doing a project.
i have a problem that is "how to access PHP variable in Javascript".

techie
Newbie Poster
2 posts since Feb 2005
Reputation Points: 10
Solved Threads: 0
 

The simplest way is to have php write the info you want into the page as javascript, for ex:

<script type="text/javascript" language="javascript">
<!--
<?php 
echo("firstVar = $var1;");
echo("2ndVar = $var2;");
?>
// -->
</script>
DanceInstructor
Posting Whiz
368 posts since Feb 2005
Reputation Points: 17
Solved Threads: 14
 

hey, you can do this simple things.

----------------------------------------------------------------------

function reset1()
{
//document.frmadd.intFaqCategoryTypeID.value='1';
document.frmadd.reset();
document.frmadd.intChatRoomCategoryId.value='<?php echo $intChatRoomCategoryId ; ?>';
document.frmadd.intEventId.value='<?php echo $intEventId ; ?>';
document.frmadd.intGroupId.value='<?php echo $intGroupId ; ?>';
document.frmadd.intMemberID.value='<?php echo $intAddedByMemberId ; ?>';
return false;
}

---------------------------------------------------------------------------------------------------------
u can reach me at [email]hetalsagar@rediffmail.com[/email]

hetalsagar
Newbie Poster
1 post since Jan 2008
Reputation Points: 10
Solved Threads: 0
 

You just bumped into a 2+ yr old thread !

nav33n
Purple hazed!
Moderator
4,465 posts since Nov 2007
Reputation Points: 524
Solved Threads: 356
 

i have two diffrent file php and html(includes javascript..) how can i access php variable in javascript using two seprate file .can u plz guid me..

samina shaikh
Newbie Poster
2 posts since Feb 2008
Reputation Points: 10
Solved Threads: 0
 

i have two diffrent file php and html(includes javascript..) how can i access php variable in javascript using two seprate file .can u plz guid me..

samina shaikh
Newbie Poster
2 posts since Feb 2008
Reputation Points: 10
Solved Threads: 0
 
i have two diffrent file php and html(includes javascript..) how can i access php variable in javascript using two seprate file .can u plz guid me..

In the php file, pass the variables you want to access into $_SESSION and then echo them as shown above.

Cilice11
Newbie Poster
1 post since Jan 2009
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You