|
Posted by shimmyshack on 03/09/07 03:01
On 9 Mar, 01:12, "kick ass" <pub_lan...@yahoo.com> wrote:
> Hello!
>
> Does anyone knows how to "copy" content of variable from java script to PHP
> variable.
> For example:
>
> JAVASCRIPT:
> <SCRIPT>
> ...if (something...blabla)
> {
> name="JACK";}
>
> </SCRIPT>
>
> Now I want to copy "JACK" into PHP variable $name.
> Can I do that?
>
> THANK YOU FOR REPLY
it all depends on what you are trying to do, I mean you can't just
copy it, you must send it, the usual way is with a form, or using XHR,
or an iframe, or a script tag, or an image.
<form id="form" action="php_script.php" method="get">
<input id="name" name="name" type="hidden" value="" />
<input name="submit" type="submit" value="submit" />
</form>
<script type="text/javascript">
//name = 'JACK';
document.getElementById('name').value = name;
document.getElementById('form').submit();
</script>
if you dont want the page to change, then submit to an iframe
<iframe src="" name="iframe" style="visibility:hidden" width="0"
height="0"></iframe>
<form id="form" action="php_script.php" method="get" target="iframe">
<input id="name" name="name" type="hidden" value="" />
<input name="submit" type="submit" value="submit" />
</form>
<script type="text/javascript">
//name = 'JACK';
document.getElementById('name').value = name;
document.getElementById('form').submit();
</script>
XHR is too boring to write out, google AJAX.
<iframe src="" id="iframe" style="visibility:hidden" width="0"
height="0"></iframe>
<script type="text/javascript">
//name = 'JACK';
document.getElementById('iframe').src = 'php_script.php?name=' + name;
</script>
<img src="" id="img" style="visibility:hidden" width="0" height="0"/>
<script type="text/javascript">
//name = 'JACK';
document.getElementById('img').src = 'php_script.php?name=' + name;
</script>
then there's the script include in the heade
<script type="text/javascript">
name = 'JACK';
document.write('<script type="text\/javascript" src="php_script.php?
name="'+name+'><\/script>');
</script>
take your pick. Of course I should be in bed so all this could be
rubbish!
Navigation:
[Reply to this message]
|