Page 1 of 1
assign javascript value to php
Posted: Mon Apr 26, 2010 7:05 am
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

Re: assign javascript value to php
Posted: Mon Apr 26, 2010 11:00 am
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.
Re: assign javascript value to php
Posted: Mon Apr 26, 2010 1:59 pm
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.
Re: assign javascript value to php
Posted: Mon Apr 26, 2010 2:15 pm
by dimxasnewfrozen
Code: Select all
$alert = 'This is an alert message';
<script language="javascript" >
alert('<?php echo $alert; ?>');
</script>
Re: assign javascript value to php
Posted: Mon Apr 26, 2010 2:52 pm
by Jonah Bron
dimxasnewfrozen, I think he's trying to pass information the other way.