Hello!
I've got a simple form with 2 fields where user will enter name and e-mail..
*********************'
<form name="formcheck" method="post" action="test.php" onSubmit="return formCheck(this);">
<p align="center"> </p>
<p align="center"> <font face="Americana BT">Navn</font>
<input type="text" name="FirstName">
</p>
<p align="center"><font face="Americana BT">E-mail</font>
<input type="text" name="email">
</p>
<p align="center">
<input name="Submit" type="submit" id="Submit" value="Ja takk, jeg vil motta nyhetsbrev per mail">
</p>
</form>
the onSubmit-action will not work ...
got the onSubmit-action from DynamicDrive.com
Got the following code under the opening- <body>-tag..
<script language="JavaScript">
<!--
/***********************************************
* Required field(s) validation v1.10- By NavSurf
* Visit Nav Surf at [url]http://navsurf.com[/url]
* Visit [url]http://www.dynamicdrive.com/[/url] for full source code
***********************************************/
function formCheck(formobj){
// Enter name of mandatory fields
var fieldRequired = Array("FirstName", "email");
// Enter field description to appear in the dialog box
var fieldDescription = Array("Navn", "email");
// dialog message
var alertMsg = "Vennligst fyll inn manglende felt:\n";
var l_Msg = alertMsg.length;
for (var i = 0; i < fieldRequired.length; i++){
var obj = formobj.elements[fieldRequired];
if (obj){
switch(obj.type){
case "select-one":
if (obj.selectedIndex == -1 || obj.options[obj.selectedIndex].text == ""){
alertMsg += " - " + fieldDescription + "\n";
}
break;
case "select-multiple":
if (obj.selectedIndex == -1){
alertMsg += " - " + fieldDescription + "\n";
}
break;
case "text":
case "textarea":
if (obj.value == "" || obj.value == null){
alertMsg += " - " + fieldDescription + "\n";
}
break;
default:
}
if (obj.type == undefined){
var blnchecked = false;
for (var j = 0; j < obj.length; j++){
if (obj[j].checked){
blnchecked = true;
}
}
if (!blnchecked){
alertMsg += " - " + fieldDescription + "\n";
}
}
}
}
if (alertMsg.length == l_Msg){
return true;
}else{
alert(alertMsg);
return false;
}
}
// -->
</script>
~Cecilie