?
Solved

Launch pop up when successful submission

Posted on 2003-03-03
6
Medium Priority
?
246 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

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

This month, Experts Exchange’s free Course of the Month is focused on CompTIA IT Fundamentals.
If you're a modern-day technology professional, you may be wondering if certifications are really necessary. They are. Here's why.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

752 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