javascript show hide div

I have input box and when the user start to type something inside of the textbox, I will a div shown.
When the user tab into other textbox, I want div hidden. and by default (on load event)
i do not want to show div.

Can you show me how it works with javascript css?

Thank you
Webboy2008Asked:
Who is Participating?
 
lpxtechConnect With a Mentor Commented:
That code is the same code. window.onload works exactly as onload=""
<script type="text/javascript>
 
window.onload = function() {
    hideDiv('myDiv');
}
 
function hideDiv(divID) {
    document.getElementById(divID).style.display = 'none';
}
 
function showDiv(divID) {
    document.getElementById(divID).style.display = 'block';
}
 
</script>

Open in new window

0
 
lpxtechCommented:
Here is some example code.

If you would like to perform an action when the focus leaves the input you can use onblur="doStuff();"
<script type="text/javascript>
 
window.onload = function() {
    hideDiv('myDiv');
}
 
function hideDiv(divID) {
    document.getElementById(divID).style.display = 'none';
}
 
function showDiv(divID) {
    document.getElementById(divID).style.display = 'block';
}
 
</script>
</head>
<html>
<input type="text" name="something" onFocus="hideDiv('myDiv');" onChange="showDiv('myDiv');" />
<div id="myDiv">
 
</div>

Open in new window

0
 
scrathcyboyCommented:
that code above won't work, all the main HTML page tags are out of place.  Simply do this --

Javascript --

function divHide()  {
document.getElementById('div1').style.display="none";
}

function divShow() {
document.getElementById('div1').style.display="block";
}
HTML --

<BODY onLoad= "divHide();" >

<input type="text" name="text1" onBlur="divHide();" onKeyUp="divShow();" >

<DIV id="div1"> this is initially hidden, but shows when input field above is changed, and disappears when mouse moved away from the input field </DIV>
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.