Click to See Complete Forum and Search --> : submit a form automatically


Plisken
07-10-2003, 01:19 PM
Hi. I want to get the users screen resolution and save it in my DB. The problem is that I can’t assign a javascript variable to a PHP variable because the PHP script is run before the javascript. So what I need is to create a javascript that can assign the screen resolution value into a hidden field in a form and then submit the form automatically. When the page is posted back to itself I can get a hold of the values that I need. I've been able to do this with a simple script that forwards the user to the same page and sends the width and height as a querystring, but I have to be able post the variables through a form. Could someone please help me here? Is it possible to have a javascript submitting a form (without the user’s knowledge)?

Thanks,
Shawn

Jona
07-10-2003, 01:32 PM
Untested code (result is a comma-delimited x and y coordinate of the screen):


<body onload="document.resForm.screen_resolution.value=window.screenX+','+window.screenY; document.resForm.submit();">
<form action="getRes.php" method="POST" name="resForm"><div>
<input type="hidden" value="" name="screen_resolution">
</div></form>
</body>


[J]ona