The Little Guy Posted October 31, 2007 Share Posted October 31, 2007 What would be the best way to send JavaScript variables to a database? My guess would be that I would have to some how pass the values off to PHP... Right? What is going to happen, is that some user takes a code I give them, then JavaScript will get some values such as screen resolution and small things like that... Screen resolution can only be gotten with JavaScript, and once it has been gotten, it needs to send the values back to my server, to save into a database... So... how is this done? Quote Link to comment https://forums.phpfreaks.com/topic/75437-javascript-save-values/ Share on other sites More sharing options...
cooldude832 Posted October 31, 2007 Share Posted October 31, 2007 a few ways. A hidden input variable sending via a form as normal in php. Ajax (this uses js vars any way) Yes screen res in php is an issue. A lot of people will "flash" on first load of a site to get the screen res store it in a session or cookie to use on all other pages. Quote Link to comment https://forums.phpfreaks.com/topic/75437-javascript-save-values/#findComment-381624 Share on other sites More sharing options...
The Little Guy Posted October 31, 2007 Author Share Posted October 31, 2007 I was looking through a file, and they use something like this: document.writeln('<script language="JavaScript" src="http://mywebsite.com/file.php?text=Somevale"></script>'); Would that work??? Quote Link to comment https://forums.phpfreaks.com/topic/75437-javascript-save-values/#findComment-381627 Share on other sites More sharing options...
cooldude832 Posted October 31, 2007 Share Posted October 31, 2007 that don't really work. the js vars are screen.width and screen.height so send an ajax query to set those to a session Quote Link to comment https://forums.phpfreaks.com/topic/75437-javascript-save-values/#findComment-381629 Share on other sites More sharing options...
The Little Guy Posted October 31, 2007 Author Share Posted October 31, 2007 It works!!! I don't see what you mean by... it doesn't work. why? Quote Link to comment https://forums.phpfreaks.com/topic/75437-javascript-save-values/#findComment-381633 Share on other sites More sharing options...
cooldude832 Posted October 31, 2007 Share Posted October 31, 2007 for screen resolution i meant Quote Link to comment https://forums.phpfreaks.com/topic/75437-javascript-save-values/#findComment-381636 Share on other sites More sharing options...
The Little Guy Posted October 31, 2007 Author Share Posted October 31, 2007 yes it will.... <script> var width=screen.width; document.writeln('<script language="JavaScript" src="http://mywebsite.com/file.php?width='+width+'"></script>'); </script> Quote Link to comment https://forums.phpfreaks.com/topic/75437-javascript-save-values/#findComment-381637 Share on other sites More sharing options...
cooldude832 Posted October 31, 2007 Share Posted October 31, 2007 u didn't write it like that originally Quote Link to comment https://forums.phpfreaks.com/topic/75437-javascript-save-values/#findComment-381640 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.