2010-05-08 95 views
0

我有一個下拉字段,如果它的任何項目被選中,它將被禁用,然後我提交表單,但(提交後)下拉字段沒有任何價值,我想有一個提交後的值,但我的下拉字段爲空。提交後,如何返回禁用的下拉字段的值?

感謝您的幫助, (對不起我的英語)

又喜。我的問題仍然存在,但無論如何感謝;使其更加清晰有我的代碼:

code: <tr> 
    <td class="tbl_entry_form_title"><%=DTask.LU_TECHNICIAN_TITLE%> :</td> 
<td class="tbl_entry_form_input"> 
<c:if test="${isTechnicianAdmin eq false}"> 
<c:forEach var="current" items="${technicianTitleItems}"> 
<c:if test="${current.value eq taskBadrItem.lu_technician_title}"> 
<input name="lu_technician_title" value="${current.value}" onclick=" 
<c:if test="${salesCustomerResult > 0}">alert('something')</c:if> 
"/></c:if> 
</c:forEach></c:if><c:if test="${isTechnicianAdmin eq true}"> 
<select name="lu_technician_title" class="select_box" onclick=" <c:if 


    test="${salesCustomerResult > 0}">alert('something')</c:if> "> 
<c:forEach var="current" items="${technicianTitleItems}"><option 
value="<c:out value="${current.value}" />"<c:if test="${current.value 
eq taskBadrItem.lu_technician_title}"> selected="selected" 
</c:if>> 


<c:out value="${current.title}"/></option></c:forEach></select> 
</c:if></td> </tr> 

回答

0

您無法獲取禁用字段的值。你可以做的一件事是通過javascript將選擇框的選擇保存在隱藏字段中,然後可以在提交表單後讀取隱藏字段的值。

例子:

<select name="whatever" id="whatever" onchange="document.getElementById('hdn').value = this.value;"> 
    <option value="value">Value</option> 
    <option value="value">Value</option> 
    <option value="value">Value</option> 
<select> 

<input type"hidden" id="hdn" /> 

現在,在你的腳本,你可以閱讀雖然hdn隱藏字段名稱選擇選項的值。

注意:在HTML標記中使用Javascript是不好的,但是您可以使用jQuery作爲不引人注意的javascript。

jQuery的例子:

$(function(){ 
    $('#whatever').change(function(){ 
    $('#hdn').val($(this).val()); 
    }); 
}); 

在這種情況下,你不需要把JavaScript代碼的HTML(選擇在這個例子中框)。

希望有所幫助。

2

假設您使用JavaScript來禁用下拉菜單,您可以將所選值複製到隱藏字段,以便將其以表格形式提交