0

I have this select dropdown. I want to check if any of the options are chosen (is value=studieretning-1 then do something).

            <select id="studieretninger" name="studieretninger">
    <option value="vælgstudieretning">Vælg din studieretning</option>
    <option class="studieretning-1" value="studieretning-1">Ma A - Fy B - Ke B</option>
    <option value="studieretning-2">Bt A - Ma A - Fy B</option>
    <option value="studieretning-3">Bi A - Ke B</option>
    <option value="studieretning-4">Sa A - Ma A</option>
</select>

I have already tried this without success, I believe it's because .val cant have arguments.

$( document ).ready(function() {
function validateDropdown()
{
    if ($("#studieretninger").val("studieretning-1"))
   {
       $(".mulighed-1").addClass("active");
       console.log(hey);
   }
}
});

How can this be done?

Joseph Cho
  • 4,033
  • 4
  • 26
  • 33

1 Answers1

0

You need to add an eventlistner on your select then see if the selected option is the studieretning-1 see code snippet

$( document ).ready(function() {
$("#studieretninger").change(function () {
    if ($(this).val()=="studieretning-1")
   {
       $(".mulighed-1").addClass("active");
       console.log("hey");
   }
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
<select id="studieretninger" name="studieretninger">
    <option value="vælgstudieretning">Vælg din studieretning</option>
    <option class="studieretning-1" value="studieretning-1">Ma A - Fy B - Ke B</option>
    <option value="studieretning-2">Bt A - Ma A - Fy B</option>
    <option value="studieretning-3">Bi A - Ke B</option>
    <option value="studieretning-4">Sa A - Ma A</option>
</select>
M0ns1f
  • 2,705
  • 3
  • 15
  • 25