change tag innerHTML based on input and length - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Input Text

Description

change tag innerHTML based on input and length

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <script>
    function myFunction(elem) {/*from  w ww. ja  v a2 s .c om*/
      var val = elem.value;
      var size = val.length;
      document.getElementById("ef1").innerHTML = size>0 ? val : "Default_Text";
    }
  
      </script> 
   </head> 
   <body> 
      <form action="#"> 
         <fieldset> 
            <legend id="ef1">Default_Text</legend> 
            <input type="text" id="inputdatahere" oninput="myFunction(this)"> 
         </fieldset> 
      </form>  
   </body>
</html>

Related Tutorials