-3

I have the html form:

<select id="selection" name="type">
    <option value="Interior">Interior</option>
    <option value="Music">Music</option>
</select>
<select id="whichvideo" name="vidtype">
    <option value="">Choose video type</option>
    <option value="Youtube">Youtube</option>
    <option value="Vimeo">Vimeo</option>
    <option id="soundcloud1" value="Soundcloud">Soundcloud</option>
</select>

and the jquery:

$("#selection").change(function () {
    if ($(this).find("option:selected").val() === "Music") {
        $("#soundcloud1").show();
    } else {
        $("#soundcloud1").hide();
    }
});

with this Fiddle

Why when I select Music and then return to Interior in the form. Does it not hide the option Soundcloud

maxisme
  • 3,974
  • 9
  • 47
  • 97

3 Answers3

0

This is working fine for me in firefox 30.

Working Fiddle

I have just added jQuery library in the fiddle. Let me know if you are looking for something else.

Aamir Shahzad
  • 6,683
  • 8
  • 47
  • 70
0

There were a couple problems with your fiddle:

  1. You didn't include jQuery so the JS wasn't working at all.
  2. You have a select in a select

Here's an updated version: http://jsfiddle.net/Xg5gU/3/

<select id="selection" name="type">
    <option value=".......">.......</option>
    <option value="Art">Art</option>
    <option value="Architecture">Architecture</option>
    <option value="Bikes">Bikes</option>
    <option value="Fashion">Fashion</option>
    <option value="Films">Films</option>
    <option value="Food">Food</option>
    <option value="Games">Games</option>
    <option value="Interior">Interior</option>
    <option value="Music">Music</option>
    <option value="Photography">Photography</option>
    <option value="Technology">Technology</option>
    <option value="Video">Video</option>
</select>

<select id="whichvideo" name="vidtype">
    <option value="">Choose video type</option>
    <option value="Youtube">Youtube</option>
    <option value="Vimeo">Vimeo</option>
    <option id="soundcloud" value="Soundcloud">Soundcloud</option>
</select>

$("#selection").change(function () {
    if ($(this).find("option:selected").val() === "Music") {
        $("#soundcloud").show();
    } else {
        $("#soundcloud").hide();
    }
});
Tom Prats
  • 7,364
  • 9
  • 47
  • 77
0

You will not get this to work across different browsers. You can store a copy of the select before removal.

More info

DEMO:

Works in Firefox, however Chrome does not support this

$("#selection").change(function () {   
    if ($(this).val() === "Music") {
        $("#whichvideo option[value='Soundcloud']").show();
    } else {       
        $("#whichvideo option[value='Soundcloud']").hide();
    }
});
Community
  • 1
  • 1
martynas
  • 12,120
  • 3
  • 55
  • 60