assign javascript value to php

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
thamizh
Forum Newbie
Posts: 18
Joined: Wed Apr 14, 2010 7:25 am

assign javascript value to php

Post by thamizh »

alert (namelist);
am having a js function which returns the a value
i want to assign this value to a php value
for eg $test = namelist;
i tried this code
<?php $test = ?> namelist;
it shows an syntax error
how can i achieve the desired result
any body help pls :(
abushahin
Forum Commoner
Posts: 42
Joined: Wed Nov 25, 2009 12:35 pm
Location: london

Re: assign javascript value to php

Post by abushahin »

hey, ur question is unclear or atleast I dont understand it.
Anyway im guessing you want to take a value from a html page that comes from a javascript source?
if thats the case then you can have a html form that uses GET or POST to send to the php page.
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: assign javascript value to php

Post by Jonah Bron »

abushahin is right. You cannot give Javascript to PHP like that. You must either a) do as abushahin suggested, or b) use ajax.
dimxasnewfrozen
Forum Commoner
Posts: 84
Joined: Fri Oct 30, 2009 1:21 pm

Re: assign javascript value to php

Post by dimxasnewfrozen »

Code: Select all

$alert = 'This is an alert message';

<script language="javascript" >
  alert('<?php echo $alert; ?>');
</script>
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: assign javascript value to php

Post by Jonah Bron »

dimxasnewfrozen, I think he's trying to pass information the other way.
Post Reply