INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

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: 28 Mar 03 (Edited 1 May 03)

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":


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":


<!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":


<!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

Back to Javascript FAQ Index
Back to Javascript Forum

My Archive

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close