BruceyBandit
BruceyBandit

Reputation: 4334

I want to hide user's name and age when page is open

I have a radio button which is yes and no. If user chooses yes then it displays user's name and age, if selected no then it wouldn't not display name or age. This works fine but when the page is open, obviously none of the two radio buttons are selected but the name and age is visible, so what I want to know is how by default when the page is open do I code it so that the user's name and age is hidden rather than visible?

function getMsg() {
                var choice = document.getElementsByName("choice");               
                var userName = document.getElementById("userName");
                var userAge = document.getElementById("userAge");

                if(choice[0].checked == true){
                    userName.style.visibility = "visible";
                    userAge.style.visibility = "visible";

                }else{
                    userName.style.visibility = "hidden";
                    userAge.style.visibility = "hidden";
            }
        }

Upvotes: 0

Views: 60

Answers (2)

Hanlet Escaño
Hanlet Escaño

Reputation: 17380

please use style="display:none" and see if that work. If not try with jQuery $("#userName").hide();. Good luck!

Upvotes: 0

egrunin
egrunin

Reputation: 25073

In the elements you want to start as hidden, use style="visibility:hidden;".

Upvotes: 2

Related Questions