Log in

View Full Version : Quick Stupid Question



viper102464
06-20-2006, 02:44 AM
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:


<form action="order.php" method="post" onSubmit="submitonce(this); return formCheck(this);">

Please help. Thanks.:)

tech_support
06-20-2006, 06:29 AM
Please have a link to the scripts your talking about :)

viper102464
06-20-2006, 07:20 AM
Sorry, here are the main parts of the page im talking about:


<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.:confused:

tech_support
06-20-2006, 07:22 AM
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 ;)

viper102464
06-20-2006, 07:30 AM
But its javascript, I thought if it is javascript related you post in this thread?:confused:

tech_support
06-20-2006, 09:35 AM
But its javascript, I thought if it is javascript related you post in this thread?:confused:
But it does have a DD script doesn't it? :confused:

djr33
06-20-2006, 05:49 PM
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.

<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 (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 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;
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.