html - Hiding other elements by one input field - Javascript -
Please provide me some small help with my Javascript code. I have an input field that hides the div element, if it is completely empty (without text):
if (search_value! == "") {document.getElementById (" Frei "). ClassName = "Free 1"; }
This does exactly what I want, the main problem is once activated by typing in the input field and when my input does not empty, my hidden divan appears , Even if there is no text in the input (because I erase it). This function is good only on first page loads, when I type something in input and erase it, then my javascript code is not functional.
Would you please advise me how does the JavaScript code look like that there is no text in every input field in the DIV? Even when the text was deleted manually?
Thank you very much and apologize for that kind of question. Iam is not strong in the original javascript.
This code will only be executed on the page load, even if you want it to Run in the input, you can use the onkeyup
event:
document. GetElementById ("yourInput") to do this. Onkeyup = function () {If (this.value! == "") {document.getElementById ("frei") ClassName = "frei1"; } And {document.getElementById ("frei"). ClassName = ""; }};
If you also need to run on page load, remove it on a function and then you can also call the function on page load: / P>
function set display (if (document.getElementById ("yourInput"). Value! == "") {document.getElementById ("frei"). ClassName = "frei1";} And {document.getElementById ("frei"). ClassName = "";}}
Then call it on page load:
setDisplay () ;
However, as we did in the first example: onkeyup
event:
document.getElementById ("yourInput") .onk Eyup = setDisplay;
Comments
Post a Comment