A2xA Posted September 16, 2008 Share Posted September 16, 2008 I'm using a chat script I've made and the script has 2 seperate files the hub.php and the chat.php page. The hub.php has the form and sends the info to the chat.php page where it adds to the chat. I need the hub.php to send a variable through javascript to the chat.php on page load and not on the form submit. What I'm passing is the page id.. Example: http://mysite.com/hub.php?id=dkjhf3883 What could I add here? I've got the id defined as $hubid in php. <div id="chat">Connecting...</div> <input id="message" type="text" size="53" maxlength="100" onkeyup="keyup(event);" /> <input type="button" value="Submit" onclick="chat_write();" /><br /> <script language="JavaScript" type="text/javascript" src="./chat.php"></script> Thanks! if you need more of the script or don't understand feel free to ask. Link to comment https://forums.phpfreaks.com/topic/124404-passing-the-id-php-variable-on-page-load/ Share on other sites More sharing options...
F1Fan Posted September 17, 2008 Share Posted September 17, 2008 Is the chat.php file a PHP file that generates Javascript code? You could try two things. Either <script language="JavaScript" type="text/javascript" src="./chat.php?id=<?=$hubid?>"></script> or something completely different, like an include. Like this (in place of the <script> line): <script language="JavaScript" type="text/javascript"> <?php include ("./chat.php?id=$hubid"); ?> </script> Link to comment https://forums.phpfreaks.com/topic/124404-passing-the-id-php-variable-on-page-load/#findComment-643490 Share on other sites More sharing options...
A2xA Posted September 19, 2008 Author Share Posted September 19, 2008 Yep. Thanks a whole lot. I tried those and on my chat.php page I put a $hubid = $_GET['id']; And the chat is generating a txt file so I'm putting this code $fn = $hubid.txt; It's just creating a .txt file. I'm not sure how I grab the variable :-\ Link to comment https://forums.phpfreaks.com/topic/124404-passing-the-id-php-variable-on-page-load/#findComment-646003 Share on other sites More sharing options...
F1Fan Posted September 19, 2008 Share Posted September 19, 2008 Not sure what you're asking. You want the variable to be passed into the TXT file? Link to comment https://forums.phpfreaks.com/topic/124404-passing-the-id-php-variable-on-page-load/#findComment-646023 Share on other sites More sharing options...
A2xA Posted September 20, 2008 Author Share Posted September 20, 2008 no, the hub.php page is trying to pass the variable to the chat.php page. Link to comment https://forums.phpfreaks.com/topic/124404-passing-the-id-php-variable-on-page-load/#findComment-646121 Share on other sites More sharing options...
Zane Posted September 20, 2008 Share Posted September 20, 2008 Why through Javascript? why not just use a header() function header("Location: chat.php?id=" . $_GET['id'] Link to comment https://forums.phpfreaks.com/topic/124404-passing-the-id-php-variable-on-page-load/#findComment-646135 Share on other sites More sharing options...
F1Fan Posted September 20, 2008 Share Posted September 20, 2008 Either way should still work. I use javascript and PHP together daily without issue. Link to comment https://forums.phpfreaks.com/topic/124404-passing-the-id-php-variable-on-page-load/#findComment-646164 Share on other sites More sharing options...
Zane Posted September 20, 2008 Share Posted September 20, 2008 I'm just saying, that unless you have a specify crucial reason to use it There is no point in using javascript.... If we knew why he was passing it to Javascript in the first place, I'm sure things would make more sense Link to comment https://forums.phpfreaks.com/topic/124404-passing-the-id-php-variable-on-page-load/#findComment-646172 Share on other sites More sharing options...
F1Fan Posted September 20, 2008 Share Posted September 20, 2008 Absolutely. If your whole code it PHP, write it in PHP. I guess I'm trying to give him the benefit of the doubt and assume that there's a bunch of other JS that is being used. I haven't learned yet! Link to comment https://forums.phpfreaks.com/topic/124404-passing-the-id-php-variable-on-page-load/#findComment-646173 Share on other sites More sharing options...
Zane Posted September 20, 2008 Share Posted September 20, 2008 Well, he's already double posted in the PHP Help forum anyway and got the answer he wanted so this thread is locked now http://www.phpfreaks.com/forums/index.php/topic,217439.0.html Link to comment https://forums.phpfreaks.com/topic/124404-passing-the-id-php-variable-on-page-load/#findComment-646185 Share on other sites More sharing options...
Recommended Posts