Vigilant Psyche Posted May 18, 2008 Share Posted May 18, 2008 I'm making this little chat room thing and I used echo("<meta http-equiv=\"refresh\" content=\"7;url=http://www.mysite.com?body=chat\">"); to refresh every 7 seconds but sometimes you're trying to type when it refreshes... Is there a way to check if the user has selected the field (<input type='text' name='chat' class=generic_black'>) before refreshing? Quote Link to comment https://forums.phpfreaks.com/topic/106191-refresh-if-the-user-hasnt-clicked-on-an-input-field/ Share on other sites More sharing options...
MadTechie Posted May 18, 2008 Share Posted May 18, 2008 maybe consider ajax or frames, if you have the text entry, in one frame and the chat window in another you won't need to update the entry frame, either that or a javascript solution, not really php Quote Link to comment https://forums.phpfreaks.com/topic/106191-refresh-if-the-user-hasnt-clicked-on-an-input-field/#findComment-544282 Share on other sites More sharing options...
GingerRobot Posted May 18, 2008 Share Posted May 18, 2008 Yes, it could be done. My javsacript is a touch rusty, but i think it would require a bit of work. As far as i'm aware, there's no simple way of checking if an element is in focus. Instead, you would have to set a variable to true using the onFocus event and then set it to false with onBlur. You would then need to use the settimeout() function every 7 seconds to call another function which would check the above value and reload only when required. My recommendation: switch to loading the chat content with AJAX. It'd be less resource intensive, and much nicer for the user. If you google for AJAX chat rooms im sure you'll find some examples to follow. Quote Link to comment https://forums.phpfreaks.com/topic/106191-refresh-if-the-user-hasnt-clicked-on-an-input-field/#findComment-544283 Share on other sites More sharing options...
runnerjp Posted May 18, 2008 Share Posted May 18, 2008 i use frames for updating after submit.. very easy to do Quote Link to comment https://forums.phpfreaks.com/topic/106191-refresh-if-the-user-hasnt-clicked-on-an-input-field/#findComment-544286 Share on other sites More sharing options...
Vigilant Psyche Posted May 18, 2008 Author Share Posted May 18, 2008 I had a look at some of the AJAX chat examples and I'm very confused . Does anyone have some very basic code for this? (Just the bare bones)... Quote Link to comment https://forums.phpfreaks.com/topic/106191-refresh-if-the-user-hasnt-clicked-on-an-input-field/#findComment-544288 Share on other sites More sharing options...
marcusfaye87 Posted May 18, 2008 Share Posted May 18, 2008 It think you have to make the page refresh a JavaScript function, that disables count if the user clicks on a field. For example: <input type="text" name="field" value="value" OnClick="stopTime('true');" And the stop time function should have a counter that automatically runs UNLESS a it is called again with a set BOOLEAN My JS is VERY VERY rusty so I won't write the function. Hope it helps Modification: Using AJAX is probably better because it allows you to update specific parts of your webpage without refreshing, But I only just started learning AJAX, so I really can't help further on that, sorry Quote Link to comment https://forums.phpfreaks.com/topic/106191-refresh-if-the-user-hasnt-clicked-on-an-input-field/#findComment-544290 Share on other sites More sharing options...
MadTechie Posted May 18, 2008 Share Posted May 18, 2008 the reason i said frames is because they are easy.. ajax would be better but its a larger learning curve.. with frames your have 3 files main.html <-- main container loads next two controls.php <-- controls to add text chatview.php <-- this you have your metatag <frameset rows="100px,*"> <frame name="control" src="controls.php"> <frame name="chat" src="chatview.php"> </frameset> *untested Quote Link to comment https://forums.phpfreaks.com/topic/106191-refresh-if-the-user-hasnt-clicked-on-an-input-field/#findComment-544305 Share on other sites More sharing options...
Vigilant Psyche Posted May 18, 2008 Author Share Posted May 18, 2008 So you're saying I should just refresh a frame as opposed to the whole page? Quote Link to comment https://forums.phpfreaks.com/topic/106191-refresh-if-the-user-hasnt-clicked-on-an-input-field/#findComment-544314 Share on other sites More sharing options...
marcusfaye87 Posted May 18, 2008 Share Posted May 18, 2008 So you're saying I should just refresh a frame as opposed to the whole page? It's a possibility, but I strongly suggest Learning AJAX to pull this off, refreshing frames is more annoying for the user browsing your page. With ajax you can update information without refreshing you entire page using XML objects. Granted it's not that easy to learn, but if you search there are some good video tutorials. Quote Link to comment https://forums.phpfreaks.com/topic/106191-refresh-if-the-user-hasnt-clicked-on-an-input-field/#findComment-544318 Share on other sites More sharing options...
MadTechie Posted May 18, 2008 Share Posted May 18, 2008 well each frame is a page, if that page has a refesh then it will only refesh itself not the whole page.. i'll like to pointout while this solution will work, i would recommend learning ajax as it would probably be better in the long run Quote Link to comment https://forums.phpfreaks.com/topic/106191-refresh-if-the-user-hasnt-clicked-on-an-input-field/#findComment-544319 Share on other sites More sharing options...
Vigilant Psyche Posted May 18, 2008 Author Share Posted May 18, 2008 Hmm... I think I'll just use frames for now, I don't really understand how to show database entries with AJAX. But with frames, apparently they cant be used inside body tags, but my site basically needs them so can you go: <body>stuff</body> <frame>chat</frame> <body>stuff</body> Does that work? Quote Link to comment https://forums.phpfreaks.com/topic/106191-refresh-if-the-user-hasnt-clicked-on-an-input-field/#findComment-544323 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.