Submit a Form Using JAVASCRIPT FUNTION
Hello guys! this is the first time I'm going to post a tutorial about javascript. Recently I'm studying about scripting and I bacame so addicted about it. I'm still a noob in this scripting but I still want to share some few things that I've learned. I started studying in w3schools then starting to apply it into my first php website.
So I really wanted to manipulate the way my form to be submitted so I tried to research about it and found a good tutorial at here.
so heres the code
so heres the code
<html>
<head>
<TITLE>
Sample
</TITLE>
<script type="text/javascript">
function alex(){
a=document.getElementById("num1").value;
b=document.getElementById("num2").value;
if (a=="") {
alert("walang laman");
}
else {
document.forms["transfer"].submit();
}
}
</script>
</head>
<body>
<h1>Manipulate Submit</h1>
<form action="page2.php" method="post" id="transfer">
Enter the no.: <br/> <input type="text" id="num1" /><br/>
Enter the column: <br/><input type text id="num2"/><br/>
<input type="button" onClick="alex()" value="click me" />
</form>
</body>
</html>
So how does it work? look at the form, I put an id "transfer" so that javascript function can detect it. I did not use a submit button but I manually made a button <input type="button" onClick="alex()" value="click me" /> so that it will first read my javascript before opening the new page so that if I want to add some codes and validation, I can easily handle it using javascript. In the javascript I made an if else condition, but the main element we really looking here is this document.forms["transfer"].submit(); so what does this do? It actually search a form with a name "transfer" and then activate its submit attribute.
Thank you for reading. I hope you like it.
By: Alexies Iglesia
So how does it work? look at the form, I put an id "transfer" so that javascript function can detect it. I did not use a submit button but I manually made a button <input type="button" onClick="alex()" value="click me" /> so that it will first read my javascript before opening the new page so that if I want to add some codes and validation, I can easily handle it using javascript. In the javascript I made an if else condition, but the main element we really looking here is this document.forms["transfer"].submit(); so what does this do? It actually search a form with a name "transfer" and then activate its submit attribute.
Thank you for reading. I hope you like it.
By: Alexies Iglesia

Comments:
Post a Comment
Enter your comment...