Ammy
Ammy

Reputation: 21

dropdown select value resets after onclick after submit

<select name="txt" id="txt" style="width:180px;height:27px" data-placeholder="Choose a name ..."  class="chosen-select form-control" >
  <option value="0" selected="selected"> SELECT  </option>
  <option value="1" name="1"> a </option>
  <option value="2" name="2"> b </option>
  <option value="3" name="3"> c</option>
</select>

<br />
<select name="repttype" id="repttype" style="width:180px;height:27px" data-placeholder="Choose a name ..."  class="chosen-select form-control" >
  <option value="0"> SELECT  </option>
  <option value="1" name="check1"> 1 </option>
  <option value="2" name="check2"> 2 </option>
  <option value="3" name="check3"> 3</option>
  <option value="4" name="check4"> 4</option>
</select>

<td  align='center'>
  <input type="button"  name="go" id="go" value="Show" class="btn btn-primary btn-md" onclick="issu();"/>
</td>

if I select value from 1st dropdown button then click on show I will get the result ao after getting result the same dropdown button should show default value as select

Upvotes: 0

Views: 84

Answers (2)

Ammy
Ammy

Reputation: 21

`$(''#txtrcpttype').change(function(){ $('#repttype').prop('selectedIndex' , 0); });

$(''#repttype').change(function(){ $('#txtrcpttype').prop('selectedIndex' , 0); });`

Upvotes: 1

santoshe61
santoshe61

Reputation: 815

Add following code to your issue() function,

$('#repttype').val('0');

or remove onclick attribute and add click handler to #go like below

$('#go').on('click', function(){
    $('#repttype').val('0');
    issue();
});

Note: Don't forgot to Add jQuery, also if you are using these codes in <form> than use preventDefault(); to prevent default submit action.

Upvotes: 1

Related Questions