Results 1 to 7 of 7

Thread: Quick Stupid Question

  1. #1
    Join Date
    Jun 2006
    Posts
    28
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Quick Stupid Question

    Hello, i have a form that i am using the Required field(s) validation script on and i want it to work in conjunction with the Submit Once! Form validation script, the problem is, if the person doesn't enter anything in the fields, the validation windo w will pop up, but even if you go back and fill in the information, you cant click submit, because the Submit Once! Form validation script disabled the button, here is what im telling the form to do:

    Code:
    <form action="order.php" method="post" onSubmit="submitonce(this); return formCheck(this);">
    Please help. Thanks.

  2. #2
    Join Date
    May 2006
    Location
    Sydney, Australia - Near the coast.
    Posts
    1,995
    Thanks
    0
    Thanked 8 Times in 7 Posts

    Default

    Please have a link to the scripts your talking about
    Peter - alotofstuffhere[dot]com - Email Me - Donate via PayPal - Got spare hardware? Donate 'em to me :) Just send me a PM.
    Currently: enjoying the early holidays :)
    Read before posting: FAQ | What you CAN'T do with JavaScript | Form Rules | Thread Title Naming Guide

  3. #3
    Join Date
    Jun 2006
    Posts
    28
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Sorry, here are the main parts of the page im talking about:

    Code:
    <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>
    </head>
    <body>
    <img src="../../images/PNG/logo_build_7000_confirmation.png"><br>
    <?php echo (formatItemList($items)); ?><br>
    <script language="JavaScript">
    <!--
    
    /***********************************************
    * Required field(s) validation v1.10- By NavSurf
    * Visit Nav Surf at http://navsurf.com
    * Visit http://www.dynamicdrive.com/ for full source code
    ***********************************************/
    
    function formCheck(formobj){
    	// Enter name of mandatory fields
    	var fieldRequired = Array("fname", "lname", "pn1", "pn2", "pn3", "email", "address1", "city", "state", "zip");
    	// Enter field description to appear in the dialog box
    	var fieldDescription = Array("First Name", "Last Name", "Area Code", "First Three Digits of Phone Number", "Last Four Digits of Phone Number", "Email Address", "Address", "City", "State", "Zip Code");
    	// dialog message
    	var alertMsg = "Please enter the following information:\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.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;
    	}
    }
    // -->
    </script>
    <form action="order.php" method="post" onSubmit="submitonce(this); return formCheck(this);">
    Please help, thanks, im sure its quite simple.

  4. #4
    Join Date
    May 2006
    Location
    Sydney, Australia - Near the coast.
    Posts
    1,995
    Thanks
    0
    Thanked 8 Times in 7 Posts

    Default

    I think this is the wrong part to talk about Dynamic Drive Scripts....

    You need to delete this topic and start a new one in the "Dynamic Drive Scripts Help" section
    Peter - alotofstuffhere[dot]com - Email Me - Donate via PayPal - Got spare hardware? Donate 'em to me :) Just send me a PM.
    Currently: enjoying the early holidays :)
    Read before posting: FAQ | What you CAN'T do with JavaScript | Form Rules | Thread Title Naming Guide

  5. #5
    Join Date
    Jun 2006
    Posts
    28
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    But its javascript, I thought if it is javascript related you post in this thread?

  6. #6
    Join Date
    May 2006
    Location
    Sydney, Australia - Near the coast.
    Posts
    1,995
    Thanks
    0
    Thanked 8 Times in 7 Posts

    Default

    Quote Originally Posted by viper102464
    But its javascript, I thought if it is javascript related you post in this thread?
    But it does have a DD script doesn't it?
    Peter - alotofstuffhere[dot]com - Email Me - Donate via PayPal - Got spare hardware? Donate 'em to me :) Just send me a PM.
    Currently: enjoying the early holidays :)
    Read before posting: FAQ | What you CAN'T do with JavaScript | Form Rules | Thread Title Naming Guide

  7. #7
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    there's a section for javascript questoins in general, and a section for php and for html and for css, but there's also a section dedicated to DD script question, whatever they may relate to. It keeps questions about DD scripts seperate and organized from personal or unrelated projects/questions.

    Anyway, in short, what you would need to do is add an if statement.

    in the function for the submit once, if you should just add an if all the way around the function (inside, but around everything in there) "if validation==true, then do this..." (else, do nothing).
    That should work, as long as you can get it to be timed correctly.

    This is untested, but should at least give you an idea of what I mean, if it doesn't work.
    HTML Code:
    <script>
    
    /*
    Submit Once form validation- 
    © Dynamic Drive ([url]www.dynamicdrive.com[/url])
    For full source code, usage terms, and 100's more DHTML scripts, visit [url]http://dynamicdrive.com[/url]
    */
    
    function submitonce(theform){
    if (validated == "true") { //ADD THIS
    //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
    }
    }
    }
    }//ADD THIS
    </script>
    </head>
    <body>
    <img src="../../images/PNG/logo_build_7000_confirmation.png"><br>
    <?php echo (formatItemList($items)); ?><br>
    <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("fname", "lname", "pn1", "pn2", "pn3", "email", "address1", "city", "state", "zip");
            // Enter field description to appear in the dialog box
            var fieldDescription = Array("First Name", "Last Name", "Area Code", "First Three Digits of Phone Number", "Last Four Digits of Phone Number", "Email Address", "Address", "City", "State", "Zip Code");
            // dialog message
            var alertMsg = "Please enter the following information:\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.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;
            validated = "true"; //ADD THIS
            }else{
                    alert(alertMsg);
                    return false;
            }
    }
    // -->
    </script>
    <form action="order.php" method="post" onSubmit="return formCheck(this); submitonce(this);">
    I switched the order of the calls to the functions in the form tag; that may be all you need... probably not, though.
    What I'm hoping is that will make it validate first, then do submit once.
    I also added three lines in there with "//ADD THIS" after them.
    The first is an if to check if it was validated, the second the end bracket for that, after the end of that function. That way, the top function will only run if the bottom one worked.
    The third thing I added was setting that "validated" variable to "true" so it would tell the top function that the bottom one worked.
    That's it.
    The main thing I don't know about is variable scope... if they'll work between the two functions without setting them as "global" variables, etc.
    I really don't know JS that well... just trying to help.

    Also, the bottom function (validate) has a return true/false depending on validation... I'm not sure if that will affect both functions, but if it does, then it will "return false" for both functions if it wasn't validated, making the other one not execute. But again, I don't know the specifics of how javascript deals with some of these things.

    Good luck.

    Note: Before doing anything else, just try reserving the order in which you call the functions in the form tag. That might be all you need.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •