views:

171

answers:

3

Hi, I have a drop down field that if any items of it selected,it would be disabled,after that i submit the form,but then (after submitting) the drop down field dosent have any value, I want to have a value after submit but my drop down field is empty.

Thanks for any help, (sorry for my English)

Hi again , My problem still remains but thanks anyway; to make it more clear there is my code:

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>  
A: 

You can not get the value of a disabled field. One thing you could do is that save the selection of the select box in a hidden field through javascript and then you can read the value of that hidden field after the form is submitted.

Example:

<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" />

Now in your script, you can read the value of selected option though hdn hidden field name.

Note: Using Javascript inside HTML markup is bad, however you can use jQuery for unobtrusive javascript.

jQuery Example:

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

In this case, you don't need to put javascript code in the html (select box in this example).

Hope that helps.

Sarfraz
+2  A: 

assuming that you use javascript to disable the dropdown, you can copy the selected value to a hidden field so it will be submitted with the form

Ahmed Khalaf
A: 
$(function(){
  //one of the correct way for disable selected option... ;-)
  $('select').change(function(){
    $(this , 'option:selected').attr("disabled", true );
  });

  $.ajax({
  url: 'ajax/test.html',
  success: function(data) {
  //after the ajax call, on success re-enable all disabled options
  $('select option:disabled').each(function(){
  $(this).attr("disabled", false );
  });  

  }
  }); 
});​​​​​
aSeptik