append text to action type and perform submit operation in HTML - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Input Submit

Description

append text to action type and perform submit operation in HTML

Demo Code

ResultView the demo in separate window

<html>
   <head></head>
   <body> 
      <form onsubmit="myFunction(event);" method="POST"> 
         <input type="text" name="myResource"> 
         <input type="submit" value="Submit"> 
      </form> 
      <script>
function myFunction(event) {/*from   www  . java2s . c o m*/
    event.preventDefault();
    const myResourceID = event.target.querySelector("[name=myResource]").value;
    event.target.setAttribute("action", "http://localhost:8080/downloads/" + myResourceID);
    event.target.submit();
}

      </script>  
   </body>
</html>

Related Tutorials