If input field is completed remove class jquery

213 Views Asked by At

trying to remove a validation class from dropdown depending on if a field before has been completed.

here is the code

 $('#NatCode').on('keyup', function () {
     // check if input has something in it
     if ($(this).val() != "") {

         $('#optone, #carNum').addClass('required');
     } else {
         $('#optone, #carNum').removeClass('required');
     }
 });

and here is part of the html

<div>
          <label for="NatCode" class="label">Eurotax NatCode </label>
          <input name="00N11000000KAoq" type="text" id="NatCode" maxlength="80" size="20" title="Please type your natcode."/>
</div>



<label for="model" class="label model">Marque</label>
<select id="optone" name="00N20000003bgum" size="1" onchange="setOptions(document.signup.optone.options[ document.signup.optone.selectedIndex].value);" title="Please choose a make" class="required">
    <option value="" selected="selected"></option>
    <option value="ABARTH">ABARTH</option>
    <option value="ALFA ROMEO">ALFA ROMEO</option>
    <option value="ASTON MARTIN">ASTON MARTIN</option>
    <option value="AUDI">AUDI</option>
</select>
</div>

<div>
    <label for="" class="label model">model</label>
    <select id="carNum" name="00N20000003bog1" size="1" maxlength="80" class="required">
        <option value="" selected="selected">Model of car</option>
    </select>
</div>

I'm new to jquery, am I completely missing something here?

0

There are 0 best solutions below