Button type Property - Change the type of a button to "submit": - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Button

Description

Button type Property - Change the type of a button to "submit":

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<form id="myForm" action="#">
First name: <input type="text" name="fname"><br>
Last name: <input type="text" name="lname"><br>
<button id="myBtn" type="button" value="Submit">Submit</button>
</form>//from   w ww  .  j ava 2 s  .  c om

<button onclick="myFunction()">Test</button>

<p id="demo"></p>

<script>
function myFunction() {
    var x = document.getElementById("myBtn").type = "submit";
    document.getElementById("demo").innerHTML = "The Submit button now works as it should.";
}
</script>

</body>
</html>

Related Tutorials