What are you on Taco

Of course you can disable the submit button onSubmit

<form onsubmit="this.sub.disabled = true;">
        <input type="Submit" name="sub">
</form>

Diabling the submit button onsubmit is the most common way of stopping double submits

What you don't do is this

<form onsubmit="this.sub.disabled = true;">
        <input type="Submit" name="sub" onclick="this.disabled = true">
</form>

An onClick event triggers before the submit action occurs cause the submit action 
doesn't happen until your mouse is clicked off the
button and as a result, the button becomes disabled before the submit action happens

Steve

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Taco Fleur
Sent: Wednesday, September 22, 2004 11:25 AM
To: CFAussie Mailing List
Subject: [cfaussie] RE: SOT: 3 Functions to check as form submits

Actually you cannot disable the submit button upon submit, it stops the form
from submitting, the best you can do is hide it. I usually do
onclick="this.value = 'Please wait ...';" 

A *simple* way would be to add hidden fields with the name of the field and
add _required to it (not a pretty way of doing it, but simple...) this way
cf does the checking for you


-- 
Taco Fleur
Senior Web Systems Engineer
http://www.webassociates.com


-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Carl
Sent: Wednesday, 22 September 2004 11:19 AM
To: CFAussie Mailing List
Subject: [cfaussie] SOT: 3 Functions to check as form submits

I have a form where I have to check form validation, grey out the submit
button (so they don't press submit again and again) and then open a small
window (in that order).

The form is for an upload of a file, so I know you can't use CFFORM and
required=yes in text boxes for form validation (unless I'm mistaken, this
would make things easier). And yes I do have enctype="multipart/form-data"
in the form element as well.

So I want to know how (and where I put the other scripts) to complete this
script and once all required fields are met, process the form by greying out
the submit box and then open the progress window.

If there is a simpler way of doing this, I would appreciate it a lot..

On submit gets this script OnSubmit="return formCheck(this);"

ClientEmail and EditorEmail are a text boxes, Details is a TextArea and
attachment is a file field.

function formCheck(formobj){
        // Enter name of mandatory fields
        var fieldRequired = Array("ClientEmail", "EditorEmail", "Details",
"attachment");
        // Enter field description to appear in the dialog box
        var fieldDescription = Array("Your Email Address", "Editor Email",
"Details", "Attachment");
        // 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 "file":
                                if (obj.value == "" || obj.value == null){
                                        alertMsg += " - " +
fieldDescription[i] + "\n";
                                }
                                break;
                        case "textarea":
                                if (obj.value == "" || obj.value == null){
                                        alertMsg += " - " +
fieldDescription[i] + "\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[i] + "\n";
                                }
                        }
                }
        }

        if (alertMsg.length == l_Msg){
                return true;
        }else{
                alert(alertMsg);
                return false;
        }
}


Here is the script for greying out submit button

<script>
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>

and on the Submit button itself
onClick="winopen('progress.cfm','instwin',350,150)"


and here is the script
function winopen(url,winname,x,y){
        var winleft = 150;
        var wintop = 150;
                                
        var options = "toolbar=no,scrollbars=no,resizable=no,left=" +
winleft + 
",top=" + wintop + ",width=" + x + ",height=" + y;
                                msgWindow=window.open(url,winname,options);
                        }

Thanks

Carl

---
You are currently subscribed to cfaussie as: [EMAIL PROTECTED]
To unsubscribe send a blank email to
[EMAIL PROTECTED]
Aussie Macromedia Developers: http://lists.daemon.com.au/


---
You are currently subscribed to cfaussie as: [EMAIL PROTECTED]
To unsubscribe send a blank email to [EMAIL PROTECTED]
Aussie Macromedia Developers: http://lists.daemon.com.au/


---
You are currently subscribed to cfaussie as: [EMAIL PROTECTED]
To unsubscribe send a blank email to [EMAIL PROTECTED]
Aussie Macromedia Developers: http://lists.daemon.com.au/

Reply via email to