Prepend text to input value on form submit - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Input Submit

Description

Prepend text to input value on form submit

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
   </head> 
   <body> 
      <script>
function AppendText(name) {/*from  w ww  .  ja  v  a 2 s . c  o  m*/
  var val = document.getElementsByName(name)[0];
  val.value = "Number:" + val.value;
  console.log(val.value);
}

      </script> 
      <form onsubmit="AppendText('num')">
          Enter invoice number: 
         <input type="text" name="num"> 
         <input type="submit"> 
      </form>  
   </body>
</html>

Related Tutorials