Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/363.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Javascript设置隐藏字段值;使用PHP post方法发送数据_Php_Javascript_Html_Forms_Post - Fatal编程技术网

使用Javascript设置隐藏字段值;使用PHP post方法发送数据

使用Javascript设置隐藏字段值;使用PHP post方法发送数据,php,javascript,html,forms,post,Php,Javascript,Html,Forms,Post,我需要获得用户的屏幕分辨率并将其保存到我的数据库中 我所做的是:我有一个调用的Javascript函数,它获取信息并将值传递给一个隐藏的表单字段。这就是功能: <script type="text/javascript"> function getUserData(){ var s_width=screen.width var s_height=screen.height document.getElementById('screen_width').value=s_width

我需要获得用户的屏幕分辨率并将其保存到我的数据库中

我所做的是:我有一个调用的Javascript函数,它获取信息并将值传递给一个隐藏的表单字段。这就是功能:

<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>

函数getUserData(){
var s_width=屏幕宽度
var s_高度=屏幕高度
document.getElementById('screen_width')。value=s_width
document.getElementById('screen_height')。value=s_height
}
及表格:

<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>


表单提交到同一页。当我单击“提交”并尝试回显$\u POST['screen\u width']和$\u POST['screen\u height']的值时,什么也没有发生。但当我重新提交时,这些值就在那里了。有人能告诉我我做错了什么吗?如果您有其他解决方案,我们也将不胜感激。

您检查过firebug的输出了吗?也许有一些错误?尝试在你的函数中提醒某个东西,也许在初始页面加载后它没有被调用?尝试将函数调用放在submit按钮的
onClick
或表单的
onSubmit
事件中。

自己解决了这个问题,只是加载元素后调用函数的问题。

这个代码看起来是正确的。

一定是PHP中的一些问题。您的函数调用在哪里?PHP代码与此相关吗?PHP目前所做的就是:echo$_POST['screen_width'];amccausl中,该函数在带有