azucker1
10-14-2002, 04:42 PM
I tried to use the method from a previous post to get two scripts to work successfully together onSubmit, but when I tried to add the 3rd and final script I want to use in a similar fashion it did not work. Any ideas on what I am doing wrong? (The scripts I am using and the form tag are below.)
Thanks,
Adam
The Code In Question:
In the head section:
<script>
/*
Submit Once form validation-
© Dynamic Drive (www.dynamicdrive.com)
For full source code, usage terms, and 100's more DHTML scripts, visit http://dynamicdrive.com
*/
function submitonce(theform){
//if IE 4+ or NS 6+
if (document.all||document.getElementById){
//screen thru every element in the form, and hunt down "submit" and "reset"
for (i=0;i<theform.length;i++){
var tempobj=theform.elements[i]
if(tempobj.type.toLowerCase()=="submit"||tempobj.type.toLowerCase()=="reset")
//disable em
tempobj.disabled=true
}
}
}
</script>
<!--- File Extension Type --->
<script language="javascript">
/**************************************************************/
/* You may freely distribute and modify the following code, */
/* but please don't delete the refference to my email id, so */
/* that people could ask the updates on it ... THANK YOU */
/* AUTHOR: Kochu */
/* EMAIL: rajeshkochu@hotmail.com */
/**************************************************************/
function check()
{
if(document.fileupload.requiredFileNew.value=="")
{
alert("Please select the image")
return false
}
// You can modify the file extentions to which ever file extensions you want to unblock
// Example you can modify ".jpg" extension to ".bmp" extension if you want to allow ".bmp" file to upload.
if((document.fileupload.requiredFileNew.value.lastIndexOf(".jpg")==-1) && (document.fileupload.requiredFileNew.value.lastIndexOf(".gif")==-1)) && (document.fileupload.requiredFileNew.value.lastIndexOf(".tiff")==-1)) && (document.fileupload.requiredFileNew.value.lastIndexOf(".pdf")==-1)) && (document.fileupload.requiredFileNew.value.lastIndexOf(".doc")==-1)) && (document.fileupload.requiredFileNew.value.lastIndexOf(".xls")==-1)) && (document.fileupload.requiredFileNew.value.lastIndexOf(".ppt")==-1)) && (document.fileupload.requiredFileNew.value.lastIndexOf(".pps")==-1))
{
alert("You can upload only JPG, GIF, TIFF, PDF, DOC, XLS, PPT, & PPS extention files")
return false
}
return true
}
</script>
In the body section:
<!-- Code to make fields required --!>
<script language="JavaScript">
<!--
/*
Required field(s) validation- By NavSurf
Visit NavSurf.com at http://navsurf.com
Visit http://www.dynamicdrive.com for this script
*/
function formCheck(formobj){
//1) Enter name of mandatory fields
var fieldRequired = Array("requiredFileNew", "requiredPROJDocDesc");
//2) Enter field description to appear in the dialog box
var fieldDescription = Array("Document Name", "Document Description");
//3) Enter 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>
<form action="upload_confirm.cfm" method="post" name="fileupload" enctype="multipart/form-data" onsubmit="return (formCheck(this) && check(this) && submitonce(this));">
Thanks,
Adam
The Code In Question:
In the head section:
<script>
/*
Submit Once form validation-
© Dynamic Drive (www.dynamicdrive.com)
For full source code, usage terms, and 100's more DHTML scripts, visit http://dynamicdrive.com
*/
function submitonce(theform){
//if IE 4+ or NS 6+
if (document.all||document.getElementById){
//screen thru every element in the form, and hunt down "submit" and "reset"
for (i=0;i<theform.length;i++){
var tempobj=theform.elements[i]
if(tempobj.type.toLowerCase()=="submit"||tempobj.type.toLowerCase()=="reset")
//disable em
tempobj.disabled=true
}
}
}
</script>
<!--- File Extension Type --->
<script language="javascript">
/**************************************************************/
/* You may freely distribute and modify the following code, */
/* but please don't delete the refference to my email id, so */
/* that people could ask the updates on it ... THANK YOU */
/* AUTHOR: Kochu */
/* EMAIL: rajeshkochu@hotmail.com */
/**************************************************************/
function check()
{
if(document.fileupload.requiredFileNew.value=="")
{
alert("Please select the image")
return false
}
// You can modify the file extentions to which ever file extensions you want to unblock
// Example you can modify ".jpg" extension to ".bmp" extension if you want to allow ".bmp" file to upload.
if((document.fileupload.requiredFileNew.value.lastIndexOf(".jpg")==-1) && (document.fileupload.requiredFileNew.value.lastIndexOf(".gif")==-1)) && (document.fileupload.requiredFileNew.value.lastIndexOf(".tiff")==-1)) && (document.fileupload.requiredFileNew.value.lastIndexOf(".pdf")==-1)) && (document.fileupload.requiredFileNew.value.lastIndexOf(".doc")==-1)) && (document.fileupload.requiredFileNew.value.lastIndexOf(".xls")==-1)) && (document.fileupload.requiredFileNew.value.lastIndexOf(".ppt")==-1)) && (document.fileupload.requiredFileNew.value.lastIndexOf(".pps")==-1))
{
alert("You can upload only JPG, GIF, TIFF, PDF, DOC, XLS, PPT, & PPS extention files")
return false
}
return true
}
</script>
In the body section:
<!-- Code to make fields required --!>
<script language="JavaScript">
<!--
/*
Required field(s) validation- By NavSurf
Visit NavSurf.com at http://navsurf.com
Visit http://www.dynamicdrive.com for this script
*/
function formCheck(formobj){
//1) Enter name of mandatory fields
var fieldRequired = Array("requiredFileNew", "requiredPROJDocDesc");
//2) Enter field description to appear in the dialog box
var fieldDescription = Array("Document Name", "Document Description");
//3) Enter 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>
<form action="upload_confirm.cfm" method="post" name="fileupload" enctype="multipart/form-data" onsubmit="return (formCheck(this) && check(this) && submitonce(this));">