Javascript form
Hey! I havn't been on for quite some time been learning a few stuff. Plus im in the middle of my exams. Anyway heres a tutorial on how to make the form and use javascript to submit it.
First lets look at the complete code...
PHP Code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<html>
<script language='javascript'>
function submitform(value, valuee){
if (value == "" || valuee == ""){
alert("Error, please fill in all the form!");
}else{
alert("Form succesfully filled in. Thank you " + value + " " + valuee);
document.form1.submit();
}
}
</script>
<form name='form1' method='post'>
First Name: <input type='text' name='firstname'><br>
Surname: <input type='text' name='surname'><br>
<a href='#' onclick='submitform(document.form1.firstname, document.form1.surname);' onmouseover="this.style.cursor:pointer;">Submit</a><br>
</form>
</html>
Okay lets go over it. First we have the javascript.
Javascript is very similar to php and very easy to understand if you know php.
In the js script, i first created a function called 'submitform'. In the submitform brackets i put in two variables, both undefined and both seperated by commas.
I then checked to see if the values had been set (if there was any information in them) and if there wasnt, i prompted the users browser and alerted them as to the problem.
I then done an else statement and alerted the user again about there information being submitted. Then I done a form submit thing whihc would submit the form. The form would only be submitted after the user had clicked OK on the alert prompt.
And the rest of it is just the html which you should look at to see what i done and how i ran the function.
Thanks,
if theres any problems please mention them. I havn't tested the script.