Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I pop open a "worksheet" window, and then pass the results back to the calling window?

Opening and closing a window

How do I pop open a "worksheet" window, and then pass the results back to the calling window?

by  EdwardMartinIII  Posted    (Edited  )
I love using worksheets to fill out forms, which probably makes me the IRS's best friend. Sometimes, you need to do a fairly complicated bit of programming before you can just drop a result into a worksheet. What this does is model a simple "worksheet" page, which when complete, then populates a specific field in the calling page and closes itself. Very tidy.

Save this as "Sample.js":

Code:
function Warning(Argument)
  {
    if(Argument=="open")
      {
        Win_Warning = window.open('NewQA.html', 'Win_Warning', 'top=50, screenY=50, left=50, width=365, height=400, scrollbars=no, scrollbar=no, menubar=no');
      }

    if(Argument=="close")
      {
        if (Win_Warning.closed+"" == "false")
          {
            Win_Warning.close();
          }
        else
          {
          }
      }
  }

Save this file as "NewQA.html":

Code:
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"></meta>
    <title>Add a Question</title>
  </head>
  <body bgcolor="#ddddff">
    <p><b>Add New Question</b></p>
    <form name="Formie">
      <p>Question<br /><textarea cols="40" rows="2" name="Question" id="Question"></textarea></p>
      <p>Answer<br /><textarea cols="40" rows="10" name="Answer" id="Answer"></textarea></p>
      <p><input type="button" value="Cancel" onclick="window.close();"></input> <input type="button" value="Clear Entries" onclick="Question.value=';Answer.value='"></input> <input type="button" value="Accept Entries" onclick="window.opener.document.MainForm.Question.value = Formie.Question.value; window.opener.document.MainForm.Answer.value = Formie.Answer.value; window.close();"></input></p>
    </form>
  </body>
</html>

And save this file as "Sample.html":

Code:
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"></meta>
    <title>JavaScript Sample</title>
    <script src="Sample.js" type="text/javascript"></script>
  </head>
  <body>
    <form name="MainForm">
      Question<br />
      <input type="text" size="50" name="Question" id="Question"></input><br />
      Answer<br />
      <input type="text" size="50" name="Answer" id="Answer"></input><br />
      <input type="button" value="Add Question" onclick="Warning('open');return false;"></input>
    </form>
  </body>
</html>

Run Sample.html in your browser to see how you like the action. Obviously, NewQA.html can do whatever you like, can contain whatever controls or validations you wish, etc.

Hope that helps!

Cheers,

Edward Martin III
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top