views:

171

answers:

3

What I'm looking to do is popup an "are you sure" confirmation box if the newly selected value of a dropdownlist is a certain value before I submit the form.

<select name="ListSearchType" id="ListSearchType">
    <option value="C">Closed</option>
    <option value="O">Open</option>
    <option value="P">Pending</option>
</select>

So if I had the dropdownlist like above with autopostback enabled, I'd want to popup a confirmation box if the user select 'Closed' before the form is submitted.

+2  A: 

One way that comes to my mind is instead of setting the autopostback option = true, you could manage the client event change with jquery.

Within the change handler you would check the selected option and perform a manual postback according values / user confirmation.

Claudio Redi
+2  A: 

On Form Submit Solution:

$(document).ready(function () {
  $("#yourFormID").submit(function () {
    if ($("#ListSearchType").val() == "C")) {
      if (!confirm("ARe you sure?")) {
        return false;
      }
    }
    return true;
  });
});

On Change Of Field Solution

  $(document).ready(function () {
      $("#ListSearchType").change(function () {
        if ($(this).val() == "C")) {
          if (!confirm("ARe you sure?")) {
             //Do something..disable submit, revert to original value.
          }
        }
      });
    });
John Hartsock
+2  A: 
$("#ListSearchType").onchange(function() {
    if ($(this).val() == "C") {
       var confirmed = confirm("Are you sure ?");
       if (!confirmed) {
          return false;
       }
    }
});
Mahesh Velaga