Reputation: 2624
I need close html form on javascript function. This is my html:
<form id="f" method="post" name="form">
<input type="button" value="okandclose" id="myButton" onclick='validateForm()' />
</form>
This is javascript.
function validateForm() {
var x = document.getElementById('sifOS').value;
if (x == null || x == 0 || x == "0") {
return false;
} else {
document.form.submit();
}
}
I need this on else.
Upvotes: 0
Views: 8333
Reputation: 1061
use ajax for this
after saving data in db you can hide the from , can display success message
Upvotes: 0
Reputation: 79
You should use window.close()
that will close the current browser window:
function validateForm() {
var x = document.getElementById('sifOS').value;
if (x == null || x == 0 || x == "0") {
return false;
}
else {
document.form.submit();
window.close();
}
}
Upvotes: 2