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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
lpxtechCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
HTML

From novice to tech pro — start learning today.