通过href方法将复选框的值发送到control.php文件

通过href方法将复选框的值发送到control.php文件,php,checkbox,parameters,href,Php,Checkbox,Parameters,Href,我有一个用于网络摄像头的control.php文件,我可以使用图像地图的href链接向其发送命令,如下所示: href=“command.php?cmd=1”。php中有一个睡眠计时器,它在1秒后停止相机的移动。一切都很好。现在,我想在webcams流媒体页面中添加一个复选框,并希望将该复选框的值发送到command.php以及comnand。它会在一秒钟后停止凸轮的移动,或者不停止,具体取决于复选框的值。我尝试了所有的php,甚至JS,但我太愚蠢了,无法完成。非常感谢您的帮助!干杯,福尔克您可

我有一个用于网络摄像头的control.php文件,我可以使用图像地图的href链接向其发送命令,如下所示:
href=“command.php?cmd=1”。php中有一个睡眠计时器,它在1秒后停止相机的移动。一切都很好。现在,我想在webcams流媒体页面中添加一个复选框,并希望将该复选框的值发送到command.php以及comnand。它会在一秒钟后停止凸轮的移动,或者不停止,具体取决于复选框的值。我尝试了所有的php,甚至JS,但我太愚蠢了,无法完成。非常感谢您的帮助!干杯,福尔克

您可以在复选框上使用javascript事件onclick(),并对第二个PHP脚本进行AJAX调用。使用
可将复选框对象及其数据作为参数传递

<input type='checkbox' onclick='moveCamera(this);'>

<script>
    function moveCamera(checkbox) {
       var http = new XMLHttpRequest();
       var url = 'command.php';
       var params = 'cmd=1&checked=' + checkbox.checked;

       http.open('POST', url, true);
       http.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
       http.onreadystatechange = function() {
           if(http.readyState == 4 && http.status == 200) {
           // Here you can put code that will be executed after the call is complete
           }
       }
       http.send(params)
    }
</script>

功能移动摄像机(复选框){
var http=new XMLHttpRequest();
var url='command.php';
var params='cmd=1&checked='+checkbox.checked;
http.open('POST',url,true);
http.setRequestHeader('Content-type','application/x-www-form-urlencoded');
http.onreadystatechange=函数(){
如果(http.readyState==4&&http.status==200){
//在这里,您可以放置调用完成后将执行的代码
}
}
http.send(params)
}

现在您可以访问
checked
,就像第二个php脚本中的
cmd
一样。

非常感谢Christoper!也许我对我不能做的事情不够精确。这就是目前行之有效的方法:

<center><h3 class="auto-style21">Camera Control 
<input type="checkbox" id="myCheck" onclick="myFunction()" checked="checked"> AutoStop aktiviert: <i id="demo"></i></h3>

<script>
function myFunction() {
var x = document.getElementById("myCheck").checked;
document.getElementById("demo").innerHTML = x;
}
</script>
摄像机控制
AutoStop aktiviert:
函数myFunction(){
var x=document.getElementById(“myCheck”).checked;
document.getElementById(“demo”).innerHTML=x;
}
但是现在,我想发送x值,而不是发送auto=true或false,请参见以下内容:

<map name="image-map">
<img src="ptz.jpg" usemap="#image-map">
<area alt="Up" title="Up" target="control" coords="127,31,25" shape="circ" 
href="control.php?cmd=0&auto=false">
<area alt="Down" title="Down" target="control" coords="127,170,30" shape="circ" 
href="control.php?cmd=2&auto=false">
<area alt="Left" title="Left" target="control" coords="39,93,30" shape="circ" 
href="control.php?cmd=4&auto=false">
<area alt="Right" title="Right" target="control" coords="217,93,25" shape="circ" 
href="control.php?cmd=6&auto=false">
<area alt="UpRight" title="UpRight" target="control" coords="181,49,22" 
shape="circ" href="control.php?cmd=91&auto=true">
<area alt="UpLeft" title="UpLeft" target="control" coords="71,49,22" 
shape="circ" href="control.php?cmd=90&auto=true">
<area alt="DownLeft" title="DownLeft" target="control" coords="63,144,22" 
shape="circ" href="control.php?cmd=92&auto=true">
<area alt="DownRight" title="DownRight" target="control" coords="188,144,22" 
shape="circ" href="control.php?cmd=93&auto=true">
<area alt="Stop" title="Stop" target="control" coords="126,95,46" shape="circ" 
href="control.php?cmd=1&auto=true">
</map>
</center>

我试过document.write,但同样,我太笨了,无法使用疯狂的语法。 document.getElementById-->InnerHTML工作正常,这是现在的解决方案,以防有人好奇:

<script>
function myFunction() {
var x = document.getElementById("myCheck").checked;
document.getElementById("demo").innerHTML = x;
var up = "<area alt=\"Up\" title=\"Up\" target=\"control\" 
coords=\"127,31,25\" shape=\"circ\" href=\"control.php?cmd=0&auto=";
var down = "<area alt=\"Down\" title=\"Down\" target=\"control\" 
coords=\"127,170,30\" shape=\"circ\" href=\"control.php?cmd=2&auto=";
var left = "<area alt=\"Left\" title=\"Left\" target=\"control\" 
coords=\"39,93,30\" shape=\"circ\" href=\"control.php?cmd=4&auto=";
var right= "<area alt=\"Right\" title=\"Right\" target=\"control\" 
coords=\"217,93,25\" shape=\"circ\" href=\"control.php?cmd=6&auto=";
var upright = "<area alt=\"UpRight\" title=\"UpRight\" target=\"control\" 
coords=\"181,49,22\" shape=\"circ\" href=\"control.php?cmd=91&auto=";
var upleft = "<area alt=\"UpLeft\" title=\"UpLeft\" target=\"control\" 
coords=\"71,49,22\" shape=\"circ\" href=\"control.php?cmd=90&auto=";
var downleft = "<area alt=\"DownLeft\" title=\"DownLeft\" target=\"control\" 
coords=\"63,144,22\" shape=\"circ\" href=\"control.php?cmd=92&auto=";
var downright= "<area alt=\"DownRight\" title=\"DownRight\" 
target=\"control\" coords=\"188,144,22\" shape=\"circ\" href=\"control.php? 
cmd=93&auto=";
var autostop = x + "\">";
document.getElementById("camup").innerHTML = up + autostop;
document.getElementById("camdown").innerHTML = down + autostop;
document.getElementById("camleft").innerHTML = left + autostop;
document.getElementById("camright").innerHTML = right + autostop;
document.getElementById("camupright").innerHTML = upright + autostop;
document.getElementById("camupleft").innerHTML = upleft + autostop;
document.getElementById("camdownleft").innerHTML = downleft + autostop;
document.getElementById("camdownright").innerHTML = downright + autostop;
}
</script>

<map name="image-map">
<img src="ptz.jpg" usemap="#image-map">
<p id="camup"></p>
<p id="camdown"></p>
<p id="camleft"></p>
<p id="camright"></p>
<p id="camupright"></p>
<p id="camupleft"></p>
<p id="camdownleft"></p>
<p id="camdownright"></p>
<!--
<area alt="Up" title="Up" target="control" coords="127,31,25" shape="circ" 
href="control.php?cmd=0&auto=false">
<area alt="Down" title="Down" target="control" coords="127,170,30" 
shape="circ" href="control.php?cmd=2&auto=false">
<area alt="Left" title="Left" target="control" coords="39,93,30" shape="circ" 
href="control.php?cmd=4&auto=false">
<area alt="Right" title="Right" target="control" coords="217,93,25" 
shape="circ" href="control.php?cmd=6&auto=false">
<area alt="UpRight" title="UpRight" target="control" coords="181,49,22" 
shape="circ" href="control.php?cmd=91&auto=true">
<area alt="UpLeft" title="UpLeft" target="control" coords="71,49,22" 
shape="circ" href="control.php?cmd=90&auto=true">
<area alt="DownLeft" title="DownLeft" target="control" coords="63,144,22" 
shape="circ" href="control.php?cmd=92&auto=true">
<area alt="DownRight" title="DownRight" target="control" coords="188,144,22" 
shape="circ" href="control.php?cmd=93&auto=true"> 
-->
<area alt="Stop" title="Stop" target="control" coords="126,95,46" 
shape="circ" href="control.php?cmd=1&auto=true">
</map>
</center>
<iframe name="control" style="display:none"></iframe>

函数myFunction(){
var x=document.getElementById(“myCheck”).checked;
document.getElementById(“demo”).innerHTML=x;
var up=”
不要忘记在身体负荷时调用myFunction


再次表示感谢和干杯,福尔克

有什么问题吗?