0

I need to get the user's screen resolution and save it my database.

What I'm doing is this: I have a Javascript function called with that gets the info and passes the value to a hidden form field. This is the function:

<script type="text/javascript">

function getUserData(){

var s_width=screen.width
var s_height=screen.height
document.getElementById('screen_width').value=s_width
document.getElementById('screen_height').value=s_height

}

</script>

And the form:

<form name="login" id="login" action="memberlogin.php" method="post">
<input type="hidden" id="screen_width" name="screen_width">
<input type="hidden" id="screen_height" name="screen_height">
<table style="margin-top:9px;">
<tr><td width="200px"><input type="text" name="username" style="width:100%"/></td></tr>
<tr><td width="200px"><input type="password" name="password" style="width:100%"/></td></tr>
<tr><td><input type="submit" name="submit" value="Log In" /></td></tr>
</table>
</form>

The form submits to the same page. When I click 'submit' and try to echo the value of $_POST['screen_width'] and $_POST['screen_height'], nothing happens. But when I re-submit it, the values are there. Can someone tell me what am I doing wrong? If you have an alternative solution, it would be equally appreciated.

4
  • this code looks correct..must be some prob in php Commented Jan 5, 2012 at 11:16
  • 1
    Where is your function called? Commented Jan 5, 2012 at 11:16
  • How is the PHP code relevant here? All PHP does at the moment is: echo $_POST['screen_width']; Commented Jan 5, 2012 at 11:16
  • amccausl, the function is called inside the <body> tag with <body onLoad="getUserData()"> Commented Jan 5, 2012 at 11:17

2 Answers 2

1

have you checked firebug's output? maybe there are some errors? try alert sth in your function, maybe it isn't called after initial page load? try putting function call in submit button's onClick or form's onSubmit event.

Sign up to request clarification or add additional context in comments.

Comments

0

Solved it myself, it was just a matter of calling the function after loading the element.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.