Jquery-How do I clear the data entered when I change the drop-down value for the default item?

advertisements

Here, I have one drop down with 3 value like 0, 1, 2 and 5 text boxes.

http://jsfiddle.net/ssthil/j4JZX/3/

when i change the drop down value, from credit card to purchase card or purchase card to credit card that time only i need to clear the entered data. not for from 0 to 1 or 0 to 2.

Added more:

I have 3 drop down value as 0, 1 and 3. And 5 more text boxes are there. By default the drop down value is 0, now i enter the data for that text boxes and i change the drop down value 0 to 1 or 2. This time shouldn't happen no more changes on those textboxes value. If i select the drop down value from 1 to 2 or 2 to 1, this time data should be clear.

Can anyone help on this required?


Save the previously selected value, compare it with the currently selected value, if there is a transition 2 -> 1 or 1 -> 2, clean up your textboxes:

 $(function(){
     var previousValue = $("select").val();
     $('select').change(function() {
         var currentValue = $(this).val();
         if (previousValue == 2 && currentValue == 1
             || previousValue == 1 && currentValue == 2) {
           $("input.textbox").val("");
         }
         previousValue = currentValue;
     });
 })‚Äč

Fiddle.