0

i am looking how to have it when i pick volvo option then the 740 is selected. i want to add other if statements but i cant not figure this out. if i pick saab i want it to select 240

I would like to use jquery or javascript

Thank you in advance. This is what i have and it does not work.

Below is the corrected code to change the drop downs.

<select id="myselect1">
  <option value="volvo">Volvo</option>
  <option value="saab">Saab</option>
  <option value="mercedes">Mercedes</option>
  <option value="audi">Audi</option>
</select>

<select id="myselectVolvo">
  <option value="740">740</option>
  <option value="940">940</option>
  <option value="240">240</option>
  <option value="340">340</option>
</select>



$('#myselect1').change(function(){


        if($('#myselect1').val() == 'volvo'){ 

        $('#myselectVolvo').val('940').trigger('change');}

       else if($('#myselect1').val() == 'saab'){
           $('#myselectVolvo').val('240').trigger('change'); }




    //alert("The text has been changed.");}
  //};
});
matthew moore
  • 215
  • 4
  • 19
  • Possible duplicate of [Use jQuery to change a second select list based on the first select list option](https://stackoverflow.com/questions/10570904/use-jquery-to-change-a-second-select-list-based-on-the-first-select-list-option) – ravibagul91 Jun 30 '19 at 05:57
  • condition in `if` is wrong you need to use `$('#myselect1').val() == 'volvo'`. You missed `.val()` after jquery selector. – Karan Jun 30 '19 at 06:00
  • Also you need to consider @Bobbey's answer and correct typo mistake. – Karan Jun 30 '19 at 06:03

1 Answers1

1

You have a typo in the last js code line. #myselctVolvo should be #myselectVolvo

your condition in if is wrong you need to use $('#myselect1').val() == 'volvo'. You missed .val() after jquery selector.

Bobbey
  • 173
  • 1
  • 4
  • 12