cappa74
asked on
Launch pop up when successful submission
Hi,
Below is a great script from TallerMike and I hoping to use it on a feedback questionnaire I'm developing, I would like to know if and how it would be possible to call another script from within your script. I have a script that produces a pop up screen thanking the user for their submission, however I'm unsure how and where to call this script, I have only been able to call this script successfully whenever the submit button is pressed but this is of no use because it also calls it if there are empty fields, I only want it to call the script when all of the fields are completed. Also I presume it will be possible to call another script when there are blank fields, to produce a pop up telling the user to fill in the missing fields.
I would appreciate any help thanks
Tony.
*** Script ***
function isRadio(inputObj)
{ return ( (inputObj.type == "radio") || (inputObj.type == "checkbox") ); }
function getRadioParent(inputObj)
{ return eval(inputObj.form.name + "." + inputObj.name); }
function highlight(inputObj,highlig htColor)
{
if ( isRadio(inputObj) )
{
inputObj = getRadioParent(inputObj);
if (inputObj.length)
for (var optionIndex=0; optionIndex < inputObj.length; optionIndex++)
{ inputObj[optionIndex].styl e.backgrou ndColor = highlightColor; }
else
{ inputObj.style.backgroundC olor = highlightColor; }
}
else
{ inputObj.style.backgroundC olor = highlightColor; }
}
function isRequired(inputObj)
{ return ( (typeof(inputObj.required) != 'undefined') && (inputObj.required != "false") ); }
function hasValue(inputObj)
{
obj_type = inputObj.type.toUpperCase( );
if (obj_type == "TEXT" || obj_type == "PASSWORD")
{ return (inputObj.value.length != 0); }
else if (obj_type == "SELECT-ONE")
{ return (inputObj.selectedIndex > 0); }
else if (obj_type == "SELECT-MULTIPLE")
{
for (var optionIndex=0; optionIndex < inputObj.length; optionIndex++)
if (inputObj.options[optionIn dex].selec ted)
{ return true; }
return false;
}
else if (obj_type == "RADIO" || obj_type == "CHECKBOX")
{
inputObj = getRadioParent(inputObj);
if (inputObj.length)
{
for (var optionIndex=0; optionIndex < inputObj.length; optionIndex++)
if (inputObj[optionIndex].che cked)
{ return true; }
return false;
}
else { return inputObj.checked; }
}
}
function check_form(formName)
{
var return_boolean = true;
var processedFields = new Array();
for(var elementIndex=0; elementIndex<formName.leng th; elementIndex++)
{
inputObj = formName.elements[elementI ndex];
if ( !(processedFields[inputObj .name] > 0) )
{
processedFields[inputObj.n ame] = 1;
if (isRequired(inputObj) && !(hasValue(inputObj)))
{
return_boolean = false;
highlight(inputObj,"red");
}
else
{ highlight(inputObj,"white" ); }
}
}
return return_boolean;
}
*** Script ***
Cheers
Below is a great script from TallerMike and I hoping to use it on a feedback questionnaire I'm developing, I would like to know if and how it would be possible to call another script from within your script. I have a script that produces a pop up screen thanking the user for their submission, however I'm unsure how and where to call this script, I have only been able to call this script successfully whenever the submit button is pressed but this is of no use because it also calls it if there are empty fields, I only want it to call the script when all of the fields are completed. Also I presume it will be possible to call another script when there are blank fields, to produce a pop up telling the user to fill in the missing fields.
I would appreciate any help thanks
Tony.
*** Script ***
function isRadio(inputObj)
{ return ( (inputObj.type == "radio") || (inputObj.type == "checkbox") ); }
function getRadioParent(inputObj)
{ return eval(inputObj.form.name + "." + inputObj.name); }
function highlight(inputObj,highlig
{
if ( isRadio(inputObj) )
{
inputObj = getRadioParent(inputObj);
if (inputObj.length)
for (var optionIndex=0; optionIndex < inputObj.length; optionIndex++)
{ inputObj[optionIndex].styl
else
{ inputObj.style.backgroundC
}
else
{ inputObj.style.backgroundC
}
function isRequired(inputObj)
{ return ( (typeof(inputObj.required)
function hasValue(inputObj)
{
obj_type = inputObj.type.toUpperCase(
if (obj_type == "TEXT" || obj_type == "PASSWORD")
{ return (inputObj.value.length != 0); }
else if (obj_type == "SELECT-ONE")
{ return (inputObj.selectedIndex > 0); }
else if (obj_type == "SELECT-MULTIPLE")
{
for (var optionIndex=0; optionIndex < inputObj.length; optionIndex++)
if (inputObj.options[optionIn
{ return true; }
return false;
}
else if (obj_type == "RADIO" || obj_type == "CHECKBOX")
{
inputObj = getRadioParent(inputObj);
if (inputObj.length)
{
for (var optionIndex=0; optionIndex < inputObj.length; optionIndex++)
if (inputObj[optionIndex].che
{ return true; }
return false;
}
else { return inputObj.checked; }
}
}
function check_form(formName)
{
var return_boolean = true;
var processedFields = new Array();
for(var elementIndex=0; elementIndex<formName.leng
{
inputObj = formName.elements[elementI
if ( !(processedFields[inputObj
{
processedFields[inputObj.n
if (isRequired(inputObj) && !(hasValue(inputObj)))
{
return_boolean = false;
highlight(inputObj,"red");
}
else
{ highlight(inputObj,"white"
}
}
return return_boolean;
}
*** Script ***
Cheers
ASKER
Thats spot on.
Tony
Tony
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
God why didn’t I think of that!! It nearly works 100% the only problem is that if the user doesn’t enter a value for a required field the error alert is output ok but when the user clicks ok it still goes to the server but I have made a few minor changes so it now stops and waits for the user to input the missing values.
function Submit_Form(FormName)
{var return_boolean = true;
if (check_form(FormName))
{
alert("Thanks for submitting!");
openindex()
return_boolean = true;
}
else
{
alert("Please fill in all required fields");
return_boolean = false;
}
return return_boolean;
}
openindex is a function that creates a html pop up.
Thanks for your assistance Mike.
Tony
function Submit_Form(FormName)
{var return_boolean = true;
if (check_form(FormName))
{
alert("Thanks for submitting!");
openindex()
return_boolean = true;
}
else
{
alert("Please fill in all required fields");
return_boolean = false;
}
return return_boolean;
}
openindex is a function that creates a html pop up.
Thanks for your assistance Mike.
Tony
ASKER
Thanks again
no problem, glad I could help.
<form onsubmit="return check_form(this)">
This would then highlight any required fields that weren't entered that were required. I'm assuming that you've got this part working correct? And what you want to do is if there are fields that the user DIDN'T enter values in, you want to put a popup that will alert them to fill in those fields. Otherwise, if they filled in everything that's required, you want to do a popup that thanks them for submitting the form. Correct?