Trying to pass a javascript variable

General discussions related to php

Moderators: macek, egami, gesf

Wilbur
New php-forum User
New php-forum User
Posts: 2
Joined: Sat Feb 15, 2003 9:40 am

Trying to pass a javascript variable

Postby Wilbur » Sat Feb 15, 2003 9:43 am

I am having great difficulty trying to pass a javascript variable to a php script which resides in the same page. I am trying to work out a way that i can pass the variable and then refresh the page - without using a link. I want the varible to be passed when the page loads.

User avatar
pootergeist
New php-forum User
New php-forum User
Posts: 191
Joined: Wed Jan 29, 2003 7:11 am
Location: UK
Contact:

Postby pootergeist » Sat Feb 15, 2003 9:58 am

javascript = clientside
php = serverside

thus php is processed before the page is sent to the client.

for javascript to pass any info to a php script requires a refresh (or possibly just a script img src swap)

maybe

<script>
document.location.replace('samepage.php?js_var=' + var);
</script>

sorta thing

Wilbur
New php-forum User
New php-forum User
Posts: 2
Joined: Sat Feb 15, 2003 9:40 am

Trying to pass a javascript variable

Postby Wilbur » Sun Feb 16, 2003 7:36 am

Thanks for the help Pootergeist.

I have incorporated the code you suggested into my script. The problem I have now is that the script is continuoslly refreshing ie it is requesting the page from the server until the stop button on the browser is pressed or a page timeout occurs.
If I rename the page that I refresh to the code works fine.

Here is my code.

<?php session_start();
session_register('rz');
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Welcome</title>

Faulty Code


<script>
var rz=screen.width;
document.location.replace('/contact/contact.php?rz=' + rz);
</script>


Faulty code finished


<script src="/csstypecont.js" language="javascript" type="text/javascript"></script>
<script src="/quick.js" language="javascript" type="text/javascript"></script>


</head>
<body background="/wtw%20.gif" ONLOAD="preloadImages();">
<?php
if ($rz==1024){
virtual ("/header.txt");
}
else if ($rz==800){
virtual ("/header2.txt");

}
?>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<?php
virtual ("contop.txt");
?>
<td colspan="3" class="blue5main"><?php
if($rz==1024){
virtual ("/nav.txt");
}
else if($rz==800){
virtual ("/nav2.txt");

}
?> </td>
</tr>
<tr>
<td colspan="3" class="blue6main">
</td>
</tr>
<?php
virtual ("coninfo.txt");
?> <tr>
<?php
virtual ("/footer.txt");
?>
</table>

</body>
</html>


Thanks in advance.


Return to “PHP General”

Who is online

Users browsing this forum: Bing [Bot] and 1 guest