【发布时间】:2018-11-21 12:59:24
【问题描述】:
我有一个 HTML 表单,我将它们的变量正确发送到 PHP 文件。我有不同的容器,有几个与地理相关的选项。这意味着,用户可以在国家/地区/经济级别的显示数据之间进行选择。为了在 PHP 中了解哪种表示方式正在过滤用户,我想使用一个额外的隐藏输入,其值为 1,2 或 3,具体取决于所选方式。我无法更改这个隐藏的输入值。
我使用以下代码:
<div class="popcountry">
<div class="funcion" onclick="country_function();setGeo()">
<h2 class="geography" style="text-align:center;" id="geoselect">Country
<input type="hidden" name="geo">
</h2>
</div>
<span class="popmenu" id="countrypopmenu">
<br>
<label class="container" style="text-align:center" id="selectControlcountry"> <b>Clear</b>
<input type="checkbox" id="selectall" />
<span class="checkmark2" style="background-color:#F0FFF0"></span>
</label>
<div class="scrollbox2">
<label class="container">Afghanistan
<input type="checkbox" id="Afghanistan" name="country[]" value="Afghanistan" checked="checked">
<span class="checkmark"></span>
</label>
<label class="container">Albania
<input type="checkbox" id="Albania" name="country[]" value="Albania" checked="checked">
<span class="checkmark"></span>
</label>
...
<div class="popregion">
<div class="funcion" onclick="region_function();setGeo2()">
<h2 class="geography" style="text-align:center" id="geoselect">Region
<input type="hidden" name="geo">
</h2>
</div>
<span class="popmenu" id="regionpopmenu">
<br>
<label class="container" style="text-align:center" id="selectControlregion"> <b>Clear</b>
<input type="checkbox" id="selectall" />
<span class="checkmark2" style="background-color:#F0FFF0"></span>
</label>
<label class="container">Africa
<input type="checkbox" id="Africa" name="region[]" value="Africa" checked="checked">
<span class="checkmark"></span>
</label>
<label class="container">Americas
<input type="checkbox" id="Americas" name="region[]" value="Americas" checked="checked">
<span class="checkmark"></span>
</label>
...
<div class="popclass">
<div class="funcion" onclick="class_function();setGeo3()">
<h2 class="geography" style="text-align:center" id="geoselect">Country Classification
<input type="hidden" name="geo">
</h2>
</div>
<span class="popmenu" id="classpopmenu">
<br>
<label class="container">Developed
<input type="checkbox" id="Developed" name="classification[]" value="Developed" checked="checked">
<span class="checkmark"></span>
</label>
<label class="container">Economies in transition
<input type="checkbox" id="Economies in transition" name="classification[]" value="Economies in transition" checked="checked">
<span class="checkmark"></span>
</label>
...
这些函数在javascript中定义为:
function setGeo(){
var geo =getElementByName("geo");
geo.value= "1";
}
function setGeo2(){
var geo =getElementByName("geo");
geo.value = "2";
}
function setGeo3(){
var geo =getElementByName("geo");
geo.value = "3";
}
有谁知道如何解决这个问题?提前致谢!
【问题讨论】:
-
发生了什么问题,你想要什么?
-
当我在 PHP 中回显地理变量时,该变量未定义。我想根据用户单击的位置更改该变量的值
-
如果您在输入上添加
id为geo,则您可以选择元素。但是,id 应该是唯一的。 -
那么,您希望当用户点击任何
geo时,此输入将被更改?不是其他geo?
标签: javascript php html forms input