Popup window

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Peter Kirk

    #1

    Popup window

    Hi,

    I want to open a popup-window which displays a list to the user. From this
    list, the user can select an item, and the data regarding this item is then
    transferred to some fields on the main window (and the popup then closes).

    But I am having several problems. I have an example "main.html" which opens
    an example "lookup.htm l". In the actual application "lookup.htm l" is
    generated dynamically be a server, and will have different lists depending
    on a "typeid" sent to the server in the request. In the example below I want
    the possibility to select from 2 lists: one called FUNCTION, and one called
    MATERIAL.

    But I can't even get the "function" data to be transferred to the main
    window. What is the problem?

    Also, what is the easiest way to tell "lookup.htm l" what fields to write to
    on the main window? The field names will be different depending on the
    particular list shown (I guess I will need to get the server which generates
    the lists to also ensure that the javascript on "lookup.htm l" matches the
    correct field names etc).

    Thanks,
    Peter



    The MAIN window (main.html):

    <html>
    <head>
    <title>
    Test Popup
    </title>
    </head>

    <script language="javas cript">
    function newWindow(url,w indow,param)
    {
    popupWindow=ope n(url, window, param);
    if (popupWindow.op ener == null) popupWindow.ope ner = self;
    }
    </script>

    <body>
    <table width="100%" border="1" bgcolor="f1f8ff ">
    <form method="post">
    <tr>
    <td valign="top" width="20%">
    <b>FUNCTION</b>
    </td>
    <td valign="top" width="40%">
    <input type="button" value="pop"
    onclick="newWin dow('lookup.htm l?typeid=5000', 'catalogue','wi dth=500,height= 4
    00')" />
    <input type="hidden" value="2" name="function" />
    <input type="text" value="f2" name="function_ shortcut"
    style="width:25 px" />&nbsp;
    <input type="text" value="function 2" name="function_ name" />
    </td>
    </tr>
    <tr>
    <td valign="top" width="20%">
    <b>MATERIAL</b>
    </td>
    <td valign="top" width="40%">
    <input type="button" value="pop"
    onclick="newWin dow('lookup.htm l?typeid=5001', 'catalogue','wi dth=500,height= 4
    00')" />
    <input type="hidden" value="11" name="material" />
    <input type="text" value="m1" name="material_ shortcut"
    style="width:25 px" />&nbsp;
    <input type="text" value="material 1" name="material_ name" />
    </td>
    </tr>
    </form>
    </table>
    </body>
    </html>



    An example POPUP window (lookup.html):

    <html>
    <head>
    <title>
    Lookup
    </title>
    </head>

    <script language="javas cript">
    function choose( id, shortcut, name )
    {
    window.opener.d ocument.forms[0].function.value = id;
    window.opener.d ocument.forms[0].function_short cut.value = shortcut;
    window.opener.d ocument.forms[0].function_name. value = name;
    window.close();
    }
    </script>

    <body>
    <table width="100%" border="1" bgcolor="f1f8ff ">
    <tr>
    <td valign="top" width="20%">
    <b>Lookup List</b>
    </td>
    <td>
    <table width="100%">
    <tr>
    <td>
    <a href="#" onclick="choose (1,'f1','functi on 1')">func 1</a>
    </td>
    </tr>
    <tr>
    <td>
    <a href="#" onclick="choose (2,'f2','functi on 2')">func 2</a>
    </td>
    </tr>
    <tr>
    <td>
    <a href="#" onclick="choose (3,'f3','functi on 3')">func 3</a>
    </td>
    </tr>
    <tr>
    <td>
    <a href="#" onclick="choose (4,'f4','functi on 4')">func 4</a>
    </td>
    </tr>
    </table>
    </td>
    </tr>
    </table>
    </body>
    </html>

  • Richard Cornford

    #2
    Re: Popup window

    Peter Kirk wrote:
    <snip>[color=blue]
    > <input type="hidden" value="2" name="function" />[/color]
    ^^^^^^^^ ^^
    If you are writing HTML why are there appendix C style XHTML space-slash
    sequences at the end of your empty tags?

    <snip>[color=blue]
    > <script language="javas cript">
    > function choose( id, shortcut, name )
    > {
    > window.opener.d ocument.forms[0].function.value = id;[/color]
    <snip> ^^^^^^^^

    Lowercase "function" is a keyword in javascript and so it cannot be used
    as an identifier. Thus it cannot appear in a dot-notation property
    accessor (that would be a syntax error). It may be used in a bracket
    notation property accessor but changing the name of the INPUT element to
    something that does not overlap with known browser property names or
    javascript key, or reserved, words would probably be the best idea.

    Richard.


    Comment

    • Peter Kirk

      #3
      Re: Popup window

      Thanks for the quick repsonse...

      "Richard Cornford" <Richard@litote s.demon.co.uk> skrev i en meddelelse
      news:cjto7p$fdd $1$830fa79d@new s.demon.co.uk.. .[color=blue]
      > Peter Kirk wrote:
      > <snip>[color=green]
      > > <input type="hidden" value="2" name="function" />[/color]
      > ^^^^^^^^ ^^
      > If you are writing HTML why are there appendix C style XHTML space-slash
      > sequences at the end of your empty tags?[/color]

      The html I posted were just "exmple" test files. Some of the people I work
      with like to put the /> at the end of these sorts of the tags. I thought
      that was the "way it was done". I admit my main problem with all this is
      that the project I am working on lacks a person who is an expert in
      javascript and html. I'm just trying to "hack" the frontend together to hook
      it up with the glorious backend code we have written :-) (sorry)

      [color=blue]
      > <snip>[color=green]
      > > <script language="javas cript">
      > > function choose( id, shortcut, name )
      > > {
      > > window.opener.d ocument.forms[0].function.value = id;[/color]
      > <snip> ^^^^^^^^
      >
      > Lowercase "function" is a keyword in javascript and so it cannot be used
      > as an identifier. Thus it cannot appear in a dot-notation property
      > accessor (that would be a syntax error). It may be used in a bracket
      > notation property accessor but changing the name of the INPUT element to
      > something that does not overlap with known browser property names or
      > javascript key, or reserved, words would probably be the best idea.[/color]

      I did wonder if this could be a problem. It appears that an input field
      called "function" is ok unless I need to access that field via javascript
      (is that the case?). Where can I find information about this "bracket
      notation property accessor" you mention. From my point of view it might be
      easier to get javascript to write to a field called "function". What about
      the "getElementById " function in javascript - would this allow me to access
      a field called "function"?

      Thanks again,
      Peter

      Comment

      • Peter Kirk

        #4
        Re: Popup window


        "Peter Kirk" <peter> skrev i en meddelelse
        news:416266db$1 @news.wineasy.s e...[color=blue]
        > Thanks for the quick repsonse...
        >
        > "Richard Cornford" <Richard@litote s.demon.co.uk> skrev i en meddelelse
        > news:cjto7p$fdd $1$830fa79d@new s.demon.co.uk.. .[color=green]
        > > Lowercase "function" is a keyword in javascript and so it cannot be used
        > > as an identifier. Thus it cannot appear in a dot-notation property
        > > accessor (that would be a syntax error). It may be used in a bracket
        > > notation property accessor but changing the name of the INPUT element to
        > > something that does not overlap with known browser property names or
        > > javascript key, or reserved, words would probably be the best idea.[/color]
        >
        > I did wonder if this could be a problem. It appears that an input field
        > called "function" is ok unless I need to access that field via javascript
        > (is that the case?). Where can I find information about this "bracket
        > notation property accessor" you mention. From my point of view it might be
        > easier to get javascript to write to a field called "function". What about
        > the "getElementById " function in javascript - would this allow me to[/color]
        access[color=blue]
        > a field called "function"?[/color]

        Hi, I now have a workable solution. (Good enough for me anyway).
        It is indeed possible to use something like this in the popup window:

        el = window.opener.d ocument.getElem entById('functi on_id')

        (where el then refers to my main window field called "function", which has
        an id "function_i d").

        Then I can set "el" to the value I want.

        Thanks,
        Peter

        Comment

        • Richard Cornford

          #5
          Re: Popup window

          Peter Kirk wrote:[color=blue]
          > Richard Cornford wrote:[color=green]
          >> Peter Kirk wrote:
          >> <snip>[color=darkred]
          >> > <input type="hidden" value="2" name="function" />[/color]
          >> ^^^^^^^^ ^^
          >> If you are writing HTML why are there appendix C style XHTML
          >> space-slash sequences at the end of your empty tags?[/color]
          >
          > The html I posted were just "exmple" test files. Some of the
          > people I work with like to put the /> at the end of these sorts
          > of the tags.[/color]

          They are required if the code is XHTML (except the space as it is only
          needed for Appendix C XHTML (which browsers don't regard as XHTML
          anyway)). In HTML they are just noise that the browser will
          error-correct out. Though apparently they are meaningful in proper SGML,
          where the slash would terminate the element and the following '>' would
          be lateral and appear in the text. To date nobody has cited a web
          browser that follows the SGML rules in this respect so it isn't a
          problem, but it is still better not to make the browser waste its time
          correcting errors.
          [color=blue]
          > I thought that was the "way it was done".[/color]

          Such nonsense in HTML source code is common, but in web authoring what
          is common is not necessarily related to the correct.
          [color=blue]
          > I admit my main problem with all this is that the project I am
          > working on lacks a person who is an expert in javascript and html.[/color]

          Is there another field of human endeavour where technical jobs are so
          routinely handed to individuals without knowledge of the technologies
          they are expected to use?
          [color=blue]
          > I'm just trying to "hack" the frontend together to hook it up
          > with the glorious backend code we have written :-) (sorry)[/color]

          There is no need to apologise, it won't have been you who made the
          strange decision.
          [color=blue][color=green]
          >> <snip>[color=darkred]
          >> > <script language="javas cript">
          >> > function choose( id, shortcut, name )
          >> > {
          >> > window.opener.d ocument.forms[0].function.value = id;[/color]
          >> <snip> ^^^^^^^^
          >>
          >> Lowercase "function" is a keyword in javascript ...[/color][/color]
          [color=blue]
          > I did wonder if this could be a problem.
          > It appears that an input
          > field called "function" is ok unless I need to access that field via
          > javascript (is that the case?).[/color]

          Yes, HTML doesn't care (name attributes are CDATA, virtually
          unrestricted) and the server side doesn't have to care either. It still
          saves a lot of trouble in the long run if form control names do not
          correspond with browser property names, javascript key and reserved
          words, etc, and conform to the format of legal javascript identifiers.
          [color=blue]
          > Where can I find information about
          > this "bracket notation property accessor" you mention.[/color]

          I should be able to say "any book on javascript", but unfortunate that
          would not be true as javascript books tend to be poor and the ones I
          have read brush over the subject, or make misleading statements about
          it. So this group's FAQ is your best bet (and the resources linked to
          from it, possibly along with the ECMAScript language specification (ECMA
          262 3rd edition):-

          <URL: http://jibbering.com/faq >

          (quick answers: (4.13) 4.25 and 4.39 directly address this subject.)
          [color=blue]
          > From my point of view it might be easier to get
          > javascript to write to a field called "function".[/color]

          Bracket notation should allow that.
          [color=blue]
          > What about the "getElementById " function in
          > javascript - would this allow me to access a field called
          > "function"?[/color]

          If 'called' means 'given an *ID* attribute of "function"' , then yes. But
          you sacrifice some back-compatibility in doing so as the -
          document.forms - collection (and contained structure) has been around
          for considerably longer than W3C DOM Core implementations .

          Richard.


          Comment

          Working...