PDA

View Full Version : Multiple Action Problems


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));">

beetle
10-14-2002, 05:14 PM
Uh....not sure what the problem is, and to be honest, I'm not going to try and figure it out. Why? Because I've spent a good amount of time on my own JS form validation tool that does everything you are trying to accomlish, and with a much bigger degree of simplicity.

Check out fValidate (http://www.peterbailey.net/fValidate) and let me know what you think.

Note: for the fileupload filetype restriction...you can use the 'custom' validator type. I can help you write the regular expression for this...

azucker1
10-14-2002, 05:26 PM
Awesome! I've been using Fvalidate for all my other forms already, though I didn't realize the custom could do what I need. Where do I start? Thanks again.

-Adam

beetle
10-14-2002, 05:43 PM
Hehe....I didn't notice until after I posted it was you, azucker :D

Here's the code you'll need for the custom....<input type="file" name="File_1" alt="custom" pattern="\.(jpg|gif|tiff|pdf|doc|xls|ppt|pps)$" emsg="You can upload only JPG, GIF, TIFF, PDF, DOC, XLS, PPT, & PPS extention files">P.S. You DO know that fValidate handles the 'submit once' thingy too, don't ya?

adios
10-14-2002, 05:43 PM
Oh, come on...........:rolleyes:

azucker1
10-14-2002, 05:47 PM
Custom works great. Thanks! And yes, I'm already using the submit once function.

-Adam:thumbsup:

beetle
10-14-2002, 05:51 PM
Originally posted by adios
Oh, come on...........:rolleyes: :confused: