I would like a JavaScript to display a DIV element if the HTML form input has a value?
-
I would like a JavaScript to display a DIV element if the HTML form input has a value. If there is no value the div is not displayed. I don't want it to display even if the text in the form input is erased. Thank you in advance.
-
Answer:
You could make a function called showHideDiv(value) or something similar. It'll check if the input-value is empty or not, and will hide the div-element if it is, and display it otherwise. Then you could add the following attribute to the input-tag: onkeyup="showHideDiv(this.value)" By doing that, you'll call the function whenever you release a key. (Backspace is also a key.) Here's an example: <html> <body> <input type="text" onkeyup="showHideDiv(this.value)"/> <script> function showHideDiv(value) { var somediv = document.getElementById('somediv'); if(value) somediv.style.display = ''; else somediv.style.display = 'none'; } </script> <div id="somediv" style="display:none;"> <h1> HELLO </h1> </div> </body> </html> ————————————— Feel free to add additional details to your question if you need any more help.
Cifru at Yahoo! Answers Visit the source
Related Q & A:
- How do I scroll to a certain widget in a QScrollArea?Best solution by Stack Overflow
- If I apply for a work Visa to work in UK, can I find a job for a 60 year old?Best solution by Yahoo! Answers
- Can I apply for a Federal job with a foreign degree?Best solution by usajobs.gov
- How can I get into a graduate program without a stellar GPA?Best solution by answers.yahoo.com
- How should I dress for a volunteer interview at a hospital?Best solution by ehow.com
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.