javascript submit button onclick code example
Example 1: HTML button onclick
<!DOCTYPE html>
<html>
<head>
<title>Title of the document</title>
</head>
<body>
<p>There is a hidden message for you. Click to see it.</p>
<button onclick="myFunction()">Click me!</button>
<p id="demo"></p>
<script>
function myFunction() {
document.getElementById("demo").innerHTML = "Hello Dear Visitor!</br> We are happy that you've chosen our website to learn programming languages. We're sure you'll become one of the best programmers in your country. Good luck to you!";
}
</script>
</body>
</html>
Example 2: button functions html
<script>
function myFunction() {
alert("ALERT");
}
</script>
<button onclick="myFunction">Click</button>
Example 3: javascript onclick
var myElem = document.getElementByID('ElemID');
myElem.onclick = function() {
//do stuff
}
Example 4: html submit form onclick
var form = document.getElementById("form-id");
document.getElementById("your-id").addEventListener("click", function () {
form.submit();
});
Example 5: input type on click submit buttom show
<button type="button" onclick="my_button_click_handler">Click this button</button>
<script>
function my_button_click_handler()
{
alert('Button Clcked');
}
</script>
Example 6: how to create a form without a submit button javascript
//you have to have the form tag in this format
<form id="myFunction" onClick= { myFunction } >
<input type="file" name="fileToUpload" id="myFunction" />
</form>
//from there you would have to create a function
function myFunction() {
document.getElementById("myFunction").submit();
}
//if this does not work, start to pray lol and do a lot of digging in
//the browser, good luck !