azucker1
10-09-2002, 10:03 PM
I'm new to JS and am trying to get two scripts to run when a form is submitted. One makes sure fields are filled in, one makes sure some fields are only numbers. I can get one or the other to work, but when I try to combine them in the form onsubmit, only the first one list works. I've tried to do as some of the online help suggests, combine them in the body tag, but then neither works. (I'm guessing that's b/c it has to do with the form, not the body of the page.) Any help is more than appreciated being that I'm running out of ideas.
Thanks for the assist,
Adam
Where I found the scripts:
Number Check: http://javascriptkit.com/script/script2/numc.shtml
Required Fields: http://navsurf.com/dhtml/formcheck.asp
Here is my current form line:
<form name="JobNumberRequest" method="post" action="jaob_number_request_confirm.cfm" onsubmit="return formCheck(this);return checkban()">
Here are the scripts:
<script language="JavaScript1.2">
/*Number check script-
By JavaScript Kit (www.javascriptkit.com)
Over 200 free scripts here!
*/
function checknumber(){
var x=document.JobNumberRequest.RequiredEstTotalFee.value
var anum=/(^\d+$)|(^\d+\.\d+$)/
if (anum.test(x))
testresult=true
else{
alert("Please input a valid number!")
testresult=false
}
return (testresult)
}
</script>
<script>
function checkban(){
if (document.layers||document.all||document.getElementById)
return checknumber()
else
return true
}
</script>
<script language="JavaScript">
<!--
// Copyright information must stay intact
// FormCheck v1.02
// Copyright NavSurf.com 2002, all rights reserved
// For more scripts, visit NavSurf.com at http://navsurf.com
function formCheck(formobj){
// name of mandatory fields
var fieldRequired = Array("requiredclientname", "requiredprojectname", "requiredLGNOffice", "requiredProjManager", "requiredProjectType", "RequiredEstTotalFee");
// field description to appear in the dialog box
var fieldDescription = Array("Client Name", "Project Name", "Profit Center", "Project Manager", "Project Type", "Est. Total Fee");
// dialog message
var alertMsg = "Please complete the following fields:\n";
var l_Msg = alertMsg.length;
for (var i = 0; i < fieldRequired.length; i++){
var obj = formobj.elements[fieldRequired[i]];
if (obj){
switch(obj.type){
case "select-one":
if (obj.selectedIndex == -1 || obj.options[obj.selectedIndex].text == ""){
alertMsg += " - " + fieldDescription[i] + "\n";
}
break;
case "select-multiple":
if (obj.selectedIndex == -1){
alertMsg += " - " + fieldDescription[i] + "\n";
}
break;
case "text":
case "textarea":
if (obj.value == "" || obj.value == null){
alertMsg += " - " + fieldDescription[i] + "\n";
}
break;
default:
if (obj.value == "" || obj.value == null){
alertMsg += " - " + fieldDescription[i] + "\n";
}
}
}
}
if (alertMsg.length == l_Msg){
return true;
}else{
alert(alertMsg);
return false;
}
}
// -->
</script>
Thanks for the assist,
Adam
Where I found the scripts:
Number Check: http://javascriptkit.com/script/script2/numc.shtml
Required Fields: http://navsurf.com/dhtml/formcheck.asp
Here is my current form line:
<form name="JobNumberRequest" method="post" action="jaob_number_request_confirm.cfm" onsubmit="return formCheck(this);return checkban()">
Here are the scripts:
<script language="JavaScript1.2">
/*Number check script-
By JavaScript Kit (www.javascriptkit.com)
Over 200 free scripts here!
*/
function checknumber(){
var x=document.JobNumberRequest.RequiredEstTotalFee.value
var anum=/(^\d+$)|(^\d+\.\d+$)/
if (anum.test(x))
testresult=true
else{
alert("Please input a valid number!")
testresult=false
}
return (testresult)
}
</script>
<script>
function checkban(){
if (document.layers||document.all||document.getElementById)
return checknumber()
else
return true
}
</script>
<script language="JavaScript">
<!--
// Copyright information must stay intact
// FormCheck v1.02
// Copyright NavSurf.com 2002, all rights reserved
// For more scripts, visit NavSurf.com at http://navsurf.com
function formCheck(formobj){
// name of mandatory fields
var fieldRequired = Array("requiredclientname", "requiredprojectname", "requiredLGNOffice", "requiredProjManager", "requiredProjectType", "RequiredEstTotalFee");
// field description to appear in the dialog box
var fieldDescription = Array("Client Name", "Project Name", "Profit Center", "Project Manager", "Project Type", "Est. Total Fee");
// dialog message
var alertMsg = "Please complete the following fields:\n";
var l_Msg = alertMsg.length;
for (var i = 0; i < fieldRequired.length; i++){
var obj = formobj.elements[fieldRequired[i]];
if (obj){
switch(obj.type){
case "select-one":
if (obj.selectedIndex == -1 || obj.options[obj.selectedIndex].text == ""){
alertMsg += " - " + fieldDescription[i] + "\n";
}
break;
case "select-multiple":
if (obj.selectedIndex == -1){
alertMsg += " - " + fieldDescription[i] + "\n";
}
break;
case "text":
case "textarea":
if (obj.value == "" || obj.value == null){
alertMsg += " - " + fieldDescription[i] + "\n";
}
break;
default:
if (obj.value == "" || obj.value == null){
alertMsg += " - " + fieldDescription[i] + "\n";
}
}
}
}
if (alertMsg.length == l_Msg){
return true;
}else{
alert(alertMsg);
return false;
}
}
// -->
</script>