0

I have a form with a couple of fields, one of then is a select with 4 options, I've a reset link to clear all fields, it works, except for the select.

I've tried a couple of options and no seems to work. Here are what I've tried without success.

$("input[name='gender']").find('option:selected').remove();

This

$('#gender').find('option:selected').removeAttr('selected"‌');

This

document.getElementById('gender').selectedIndex = -1;

I want to remove all attributes selected of option, or select the first option could be a default value.

So far I've this code to clean all inputs, I've tried the button type reset, but since I have some data returning from server, field masks and field validations running in this form I'm only able to proper empty field setting empty values to it.

$('#reset_form_link').click(function() {  
    $(':input','#client_form')
      .not(":button, :submit, :reset, :hidden[name='_token'], :hidden[name='_method']")
      .val('')
      .removeAttr('checked')
      .removeAttr('selected');
});
Big Boss
  • 250
  • 1
  • 3
  • 11
  • 1
    A standard reset button, as you said you tried, works for me. https://jsfiddle.net/j08691/9o6yngn4/. please post a [mcve] – j08691 Mar 21 '17 at 19:50
  • Possible duplicate of [How do you select a particular option in a SELECT element in jQuery?](http://stackoverflow.com/questions/314636/how-do-you-select-a-particular-option-in-a-select-element-in-jquery) – kittykittybangbang Mar 21 '17 at 19:51
  • @j08691 I have a link with a function to reset, because the reset button doesn't work since I have a couple of verification/masks scripts running in this form. I will edit the question and include the complete script I have to clear the form fields. – Big Boss Mar 21 '17 at 20:00

0 Answers0