简体   繁体   中英

HTML Javascript, checkbox toggles label and dropdown list visibility

I'm halfway to getting this correct, but i am currently stuck. Firstly i would like the label and dropdown to be hidden be default. This i have achieved using css:

#unis
{
    visibility:hidden;
}

The bit i am slightly stuck on is how to group the items, i have used:

<div class='row'>
    <div id = "unis">
        <label id='Universitylbl' for='University'>University institution:</label>
        <select name="uni">
            <option value="uni1">uni1</option>
            <option value="uni2">uni2</option>
            <option value="uni3">uni3</option>
            <option value="uni4">uni4</option>
            <option value="uni5">uni5</option>
        </select><br />
    </div>
</div>

and the javascript to toggle the visibility:

function toggle(elementID){
    var target1 = document.getElementById(elementID)
    if (target1.style.display == 'none') {
        target1.style.display = 'block'
    }
    else
         {
        target1.style.display = 'none'
    }
}

but the above code doesn't appear to work?

It seems you are assigning target2 a value and altering the display of target1 . Shouldn't that be the same object ? ( target , for example ?)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM