?
Solved

Launch pop up when successful submission

Posted on 2003-03-03
6
Medium Priority
?
250 Views
Last Modified: 2010-04-01
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,highlightColor)
    {
    if ( isRadio(inputObj) )
         {
         inputObj = getRadioParent(inputObj);
         if (inputObj.length)
              for (var optionIndex=0; optionIndex < inputObj.length; optionIndex++)
                   { inputObj[optionIndex].style.backgroundColor = highlightColor; }
         else
              { inputObj.style.backgroundColor = highlightColor; }
         }
    else
         { inputObj.style.backgroundColor = 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[optionIndex].selected)
                   { 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].checked)
                        { 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.length; elementIndex++)
         {
         inputObj = formName.elements[elementIndex];
         if ( !(processedFields[inputObj.name] > 0) )
              {
              processedFields[inputObj.name] = 1;
              if (isRequired(inputObj) && !(hasValue(inputObj)))
                   {
                   return_boolean = false;
                   highlight(inputObj,"red");
                   }
              else
                   { highlight(inputObj,"white"); }
              }
         }
    return return_boolean;
    }

*** Script ***

Cheers
0
Comment
Question by:cappa74
  • 3
  • 3
6 Comments
 
LVL 8

Expert Comment

by:TallerMike
ID: 8057651
How are you calling the script from your form? I think the original intention of the script was to script was to be called like so:

<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?
0
 

Author Comment

by:cappa74
ID: 8058576
Thats spot on.

Tony
0
 
LVL 8

Accepted Solution

by:
TallerMike earned 60 total points
ID: 8058701
OK, so what you'll need to do is to create a seperate function, like so:

function submitForm(FormName)
     {
     if (check_form(FormName))
          {
          alert("Thanks for submitting!");
          return false;
}
     else
          {
          alert("Please fill in all required fields");
          return true;
}
     }

Then change your form like so:

<form onsubmit="return submitForm(this)">

Basically, this will alert the user if they didn't fill something out, and NOT submit the form. Other wise, thank them for submitting, and then submit the form.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:cappa74
ID: 8063382
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
0
 

Author Comment

by:cappa74
ID: 8063387
Thanks again
0
 
LVL 8

Expert Comment

by:TallerMike
ID: 8064231
no problem, glad I could help.
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

As the cloud has become an integral part of enterprises’ workflow worldwide, there is an increasing demand for cloud managed service providers that can bring the expertise to the process and help enterprises maximize their investment in the cloud.
The following information will get you familiar with your new DV server, including the (mt) Account Center, the Plesk Control Panel, our world-renowned support department and the rest of the (mt) tools that come with your new service.
Kernel Data Recovery is a renowned Data Recovery solution provider which offers wide range of softwares for both enterprise and home users with its cost-effective solutions. Let's have a quick overview of the journey and data recovery tools range he…
Enter Foreign and Special Characters Enter characters you can't find on a keyboard using its ASCII code ... and learn how to make a handy reference for yourself using Excel ~ Use these codes in any Windows application! ... whether it is a Micr…
Suggested Courses

616 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question