[英]Multiaction form by select option with javascript
<form id="check" action="." method="POST">
<input id="act" type="hidden" name="action"/>
<select id="blk">
<option value="blk">Bulk Actions</option>
<option value="tes">Active</option>
<option>Inactive</option>
<option>Delete</option>
</select>
<input type="submit" value="Submit" onclick="document.getElementById('act').value = 'document.getElementById('blk').selectedIndex.value'"/>
</form>
我想通過選擇標記獲取值,並且值操作將在輸入時更改,名稱操作為值
您混合了兩個概念。
select
元素具有一個value
屬性,該屬性反映當前的選擇 document.getElementById('blk').value
select
元素具有一個帶有值的選項列表以及一個反映當前選擇位置的selectedIndex
屬性。 像這樣使用它: var sel = document.getElementById('blk');
if (sel.selectedIndex >= 0) // could be -1 as well
return sel.options[sel.selectedIndex].value
但是,您實際上想要的是
<form id="check" action="." method="POST">
<select name="action">
<option value="blk">Bulk Actions</option>
<option value="tes">Active</option>
<option>Inactive</option>
<option>Delete</option>
</select>
<input type="submit" value="Submit" />
</form>
您忘記了select
控件的name
,因此不會發布任何值。 使用它,您既不需要隱藏的輸入,也不需要按鈕上的單擊偵聽器(在表單上也應該是onsubmit
偵聽器)。
try this
<form id="check" action="." method="POST">
<input id="act" type="hidden" name="action"/>
<select id="blk" onchange="javascript:CallMe(this.value)">
<option value="blk">Bulk Actions</option>
<option value="tes">Active</option>
<option>Inactive</option>
<option>Delete</option>
</select>
<input type="submit" value="Submit" onclick="document.getElementById('act').value = 'document.getElementById('blk').selectedIndex.value'"/>
</form>
<script>
function CallMe(String str)
{
alert(str+" : is the value selected , call the according action now");
}
</script>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.