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

Recommended Answers

All 6 Replies

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>
commented: cool solution +2

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;
}

You just bumped into a 2+ yr old thread !

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..

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..

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.