[英]Pass data to send.php - select option text and value
Basically i am trying to debug this: Ihave a HTML form and a send.php from which i extract data like 基本上我想调试一下:我有一个HTML表单和一个send.php,我可以从中提取数据,例如
$locridicare= addslashes($_GET['liv']);
$locreturnare=addslashes($_GET['ret']);
$codlocridicare=addslashes($_GET['locridicare']);
$codlocreturnare=addslashes($_GET['locreturnare']);
The codlocridicare should get the VALUE and the locridicare should get the TEXT from the SELECT option called locridicare. codlocridicare应该从称为locridicare的SELECT选项中获得VALUE,而locridicare应该获得TEXT。
Same for codlocreturnare and locreturnare, from the other select. 对于codlocreturnare和locreturnare,从其他选择中相同。
The form i run: 我运行的表格:
<script>
function changelivrare (objDropDown)
{
document.getElementById("liv").value = objDropDown.value;
}
function changereturnare (objDropDown)
{
document.getElementById("ret").value = objDropDown.value;
}
</script>
and then the in form 然后是形式
<select name="locridicare" id="locridicare" onchange="changelivrare(this)">
<option value=""> --- Selectaţi --- </option>
<option value="3231">Aeroport Otopeni - Bucuresti</option>
</select>
<input type="hidden" name="liv" id="liv" />
<select name="locreturnare" id="locreturnare" onchange="changereturnare(this)" >
<option value=""> --- Selectaţi --- </option>
<option value="3231">Aeroport Otopeni - Bucuresti</option>
</select>
<input type="hidden" name="ret" id="ret" />
To get the selected option's text, use: 要获取所选选项的文本,请使用:
function changelivrare(objDropDown) {
document.getElementById("liv").value = objDropDown.options[objDropDown.selectedIndex].innerHTML;
}
objDropDown.value
is the value of the selected option, not its text. objDropDown.value
是所选选项的值,而不是其文本。 objDropDown.options
is a collection of the options, and objDropDown.selectedIndex
is the position of the selected option. objDropDown.options
是选项的集合,而objDropDown.selectedIndex
是所选选项的位置。
I also suggest you combine the two function into one: 我还建议您将两个功能合并为一个:
function textToHiddenInput(objDropDown, inputID) {
document.getElementById(inputID).value = objDropDown.options[objDropDown.selectedIndex].innerHTML;
}
Then you change the HTML to: 然后将HTML更改为:
<select name="locridicare" id="locridicare" onchange="textToHiddenInput(this, 'liv')">
...
<select name="locreturnare" id="locreturnare" onchange="textToHiddenInput(this, 'ret')" >
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.