John Doe
John Doe

Reputation: 2060

Making button hidden on page load

Without using jQuery, I want my button with the text "Process" to not be visible (in all browsers) when the visitor comes to the page. And when they select a value from the drop down other than the first entry (blank) one or Have a Baby for it to make the button visible.

<html>
<head>
<title>Life Event Picker Calendar</title>
<script>
// Function being used to hide/unhide the button
function changeMessage(oElement) {
    if (oElement.value == "100") {
        document.getElementById("btn").style.visibility = "hidden";
    } else if (oElement.value == "0") {
        document.getElementById("btn").style.visibility = "hidden";
    } else {
        document.getElementById("btn").style.visiblity = "visible";
    }
}
</script>
</head>
<body>

...
...
<!-- Based on the selection here - the button below would be made visible --> 
<select id="leave" onchange="changeMessage(this);">
  <option value="0"></option>
  <option value="5">Get Married</option>
  <option value="100">Have a Baby</option>
  <option value="90">Adopt a Child</option>
  <option value="15">Retire</option>
  <option value="15">Military Leave</option>
  <option value="15">Medical Leave</option>
</select>

 <!-- The button in question -->
 <button id="btn" onclick="getInfo()"type="button">Process</button>

...
... 

</body>
</html>

Upvotes: 0

Views: 20062

Answers (1)

Grampa
Grampa

Reputation: 1643

Try adding the style="visibility:hidden;" attribute to the button. Also, consider using display:none and display:inline-block instead of visibility.

Upvotes: 6

Related Questions