4 Replies - 8445 Views - Last Post: 12 November 2008 - 02:43 PM

#1 noname_clark  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 75
  • Joined: 22-October 08

assigning a php variable = to a javascript variable

Posted 12 November 2008 - 09:11 AM

hi, I am trying to make a php variable = to a javascript variable in java script.
example:

main.php:
<?php $a = 1; ?>
<script LANGUAGE="Javascript" TYPE="text/javascript">
<!--
var b++;

$a = b;	 <!-- this is what I want to happen so that $a is = 2, instead of 1 -->

// -->
</SCRIPT>


just as a quick example.

any ideas? I'm sure there is a way to do it, I just can't figure out how... i have tried several ways, but none of them seem to work...

thanks in advance.

Is This A Good Question/Topic? 0
  • +

Replies To: assigning a php variable = to a javascript variable

#2 xerxes333  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 31
  • View blog
  • Posts: 504
  • Joined: 05-July 07

Re: assigning a php variable = to a javascript variable

Posted 12 November 2008 - 09:51 AM

PHP is server-side and javascript is client-side the only way I know (althought that does not mean it isn't possible) is to submit the data (form) to the server so the php can get the data. If anyone knows otherwise feel free to correct me.
Was This Post Helpful? 0
  • +
  • -

#3 noname_clark  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 75
  • Joined: 22-October 08

Re: assigning a php variable = to a javascript variable

Posted 12 November 2008 - 10:47 AM

View Postxerxes333, on 12 Nov, 2008 - 08:51 AM, said:

PHP is server-side and javascript is client-side the only way I know (althought that does not mean it isn't possible) is to submit the data (form) to the server so the php can get the data. If anyone knows otherwise feel free to correct me.


ok. well thanks. I don't think that will work for what I'm trying to do without implementing a bunch of AJAX. I'll find some other way to do it.

Thanks again.
Was This Post Helpful? 0
  • +
  • -

#4 aalbiel  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 12-November 08

Re: assigning a php variable = to a javascript variable

Posted 12 November 2008 - 01:40 PM

I have used :

<script>
B="<?=$A?>";
B++;
</script>

This post has been edited by aalbiel: 12 November 2008 - 01:43 PM

Was This Post Helpful? 0
  • +
  • -

#5 xerxes333  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 31
  • View blog
  • Posts: 504
  • Joined: 05-July 07

Re: assigning a php variable = to a javascript variable

Posted 12 November 2008 - 02:43 PM

aalbiel, that works if you want to assign a a php var to a jscript var but I think he is trying to assign a jscript to a php var.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1