PHP and JAVA problem

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
kick ass [ Fr, 09 März 2007 02:12 ] [ ID #1652898 ]

Re: PHP and JAVA problem

On 9 Mar, 01:12, "kick ass" <pub_lan... [at] 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!
shimmyshack [ Fr, 09 März 2007 04:01 ] [ ID #1652899 ]

Re: PHP and JAVA problem

kick ass wrote:

> Does anyone knows how to "copy" content of variable from java script to PHP
> variable.
> For example:
>
> JAVASCRIPT:

JavaScript isn't Java, the only thing they have in common is the four first
letters in their names.

> <SCRIPT>
> ...if (something...blabla)
> {
> name="JACK";
> }
> </SCRIPT>
>
> Now I want to copy "JACK" into PHP variable $name.
> Can I do that?

You can't do that without reloading the whole script.

As shimmyshack points out there are a couple of different methods to do it,
AJAX is good if you only have to update a smaller area of your page, a form is
easy to make and quite good when updating the whole page.

--

//Aho
Shion [ Fr, 09 März 2007 08:42 ] [ ID #1652901 ]

Re: PHP and JAVA problem

THANK YOU!!
I have solved the problem,
I used "form":

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

It works just fine.


"shimmyshack" <matt.farey [at] gmail.com> wrote in message
news:1173409271.780108.308050 [at] j27g2000cwj.googlegroups.com.. .
> On 9 Mar, 01:12, "kick ass" <pub_lan... [at] 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!
>
kick ass [ Fr, 09 März 2007 16:55 ] [ ID #1652916 ]
PHP » alt.php » PHP and JAVA problem

Vorheriges Thema: Issue in the multiple textarea
Nächstes Thema: Create only one instance of Object