Close Window Function

Discussion in 'Javascript' started by clequieu@nuvell.com, Apr 13, 2005.

  1. Guest

    I have created a form. Within the form is a button to close the window
    on click and to validate as well. The close window works when it is a
    stand alone, but it does not work when it is embedded with the other
    code. Here is the code I am currently using:

    <p><font face="Trebuchet MS">
    <input type="submit" value="Send" name="B1"
    onClick="Javascript:window.close()" "MM_validateForm('Manager
    Name','','R','Managers Extension','','R','Department','','R');return
    document.MM_returnValue">
    <input type="reset" value="Clear" name="B2">
    </font></p>

    Any help you can give me will be greatly appreciated.

    Cat
     
    , Apr 13, 2005
    #1
    1. Advertising

  2. kaeli Guest

    In article <>,
    enlightened us with...
    > I have created a form. Within the form is a button to close the window
    > on click and to validate as well. The close window works when it is a
    > stand alone, but it does not work when it is embedded with the other
    > code. Here is the code I am currently using:
    >
    > <p><font face="Trebuchet MS">
    > <input type="submit" value="Send" name="B1"
    > onClick="Javascript:window.close()" "MM_validateForm('Manager
    > Name','','R','Managers Extension','','R','Department','','R');return
    > document.MM_returnValue">
    > <input type="reset" value="Clear" name="B2">
    > </font></p>
    >
    > Any help you can give me will be greatly appreciated.


    How can it validate *after* it closes itself?
    Think about it. ;)

    I think you wanted validation, then closing if successful, yes?
    And ditch the "javascript:" stuff in an event.

    <input type="submit" value="Send" name="B1"
    onClick="if (MM_validateForm('Manager
    Name','','R','Managers Extension','','R','Department','','R')) window.close
    ();>

    That assumes MM_validateForm returns a true/false or equivalent value that
    the "if" can evaluate to t/f.

    --
    --
    ~kaeli~
    You can't have everything. Where would you put it?
    http://www.ipwebdesign.net/wildAtHeart
    http://www.ipwebdesign.net/kaelisSpace
     
    kaeli, Apr 13, 2005
    #2
    1. Advertising

  3. In article <>,
    says...
    > I have created a form. Within the form is a button to close the window
    > on click and to validate as well. The close window works when it is a
    > stand alone, but it does not work when it is embedded with the other
    > code. Here is the code I am currently using:
    >
    > <p><font face="Trebuchet MS">
    > <input type="submit" value="Send" name="B1"
    > onClick="Javascript:window.close()" "MM_validateForm('Manager
    > Name','','R','Managers Extension','','R','Department','','R');return
    > document.MM_returnValue">
    > <input type="reset" value="Clear" name="B2">
    > </font></p>
    >
    > Any help you can give me will be greatly appreciated.


    Your code is screwed. javascript: isn't required - by definition
    whatever you put in the onclick even is scripting. You're trying to
    have multiple values for the onclick event - you can't. You need
    something like this:

    onClick="
    window.close();
    MM_validateForm('Manager Name','','R','Managers
    Extension','','R','Department','','R');
    return document.MM_returnValue;"

    Of course, your window will close before the validation runs anyway.
    What's the point of running a validation before you close the window -
    what happens with the form data you're trying to validate? If you're
    closing the window without performing some sort of processing on the
    input, why bother with the input at all?

    There should be an apostrophe in "Managers Extension", too, but that
    will no doubt cause you another problem.

    --
    Hywel
     
    Hywel Jenkins, Apr 13, 2005
    #3
  4. RobG Guest

    Hywel Jenkins wrote:
    > In article <>,
    > says...
    >
    >>I have created a form. Within the form is a button to close the window
    >>on click and to validate as well. The close window works when it is a
    >>stand alone, but it does not work when it is embedded with the other
    >>code. Here is the code I am currently using:
    >>
    >> <p><font face="Trebuchet MS">
    >> <input type="submit" value="Send" name="B1"
    >>onClick="Javascript:window.close()" "MM_validateForm('Manager
    >>Name','','R','Managers Extension','','R','Department','','R');return
    >>document.MM_returnValue">
    >> <input type="reset" value="Clear" name="B2">
    >> </font></p>
    >>
    >>Any help you can give me will be greatly appreciated.

    >


    [...]

    >
    > There should be an apostrophe in "Managers Extension", too, but that
    > will no doubt cause you another problem.
    >


    Not only but also...

    If "Managers Extension" is intended to be the name of a form element,
    and it seems likely that it is, then neither the space nor the
    suggested grammatically correct but syntactically erroneous
    apostrophe are legal characters.

    The HTML rules for id and name tokens are:

    "# ID and NAME tokens must begin with a letter ([A-Za-z]) and may
    be followed by any number of letters, digits ([0-9]), hyphens
    ("-"), underscores ("_"), colons (":"), and periods (".")."

    <URL:http://www.w3.org/TR/html4/types.html#type-cdata>

    i.e. spaces and quotes are not allowed as part of names or ids.

    --
    Rob
     
    RobG, Apr 14, 2005
    #4
  5. RobB Guest

    wrote:
    > I have created a form. Within the form is a button to close the

    window
    > on click and to validate as well. The close window works when it is

    a
    > stand alone, but it does not work when it is embedded with the other
    > code. Here is the code I am currently using:
    >
    > <p><font face="Trebuchet MS">
    > <input type="submit" value="Send" name="B1"
    > onClick="Javascript:window.close()" "MM_validateForm('Manager
    > Name','','R','Managers Extension','','R','Department','','R');return
    > document.MM_returnValue">
    > <input type="reset" value="Clear" name="B2">
    > </font></p>
    >
    > Any help you can give me will be greatly appreciated.
    >
    > Cat


    <body...onunload="self.close()">
    ...............
    ...............
    <form....onsubmit="MM_validateForm('Manager
    Name','','R','Managers Extension','','R','Department','','R');return
    document.MM_returnValue">
    ........
    ........
    <input type="submit" value="Send" name="B1">
    <input type="reset" value="Clear" name="B2">
     
    RobB, Apr 14, 2005
    #5
  6. RobG wrote:
    > Hywel Jenkins wrote:

    <sbnip>
    >> There should be an apostrophe in "Managers Extension", too,
    >> but that will no doubt cause you another problem.
    >>

    >
    > Not only but also...
    >
    > If "Managers Extension" is intended to be the name of a form
    > element, and it seems likely that it is, then neither the space nor
    > the suggested grammatically correct but syntactically erroneous
    > apostrophe are legal characters.


    The name attributes of A, MAP, IMG, OBJECT, PARAM, APPLET, FORM, INPUT,
    SELECT, TEXTAREA, BUTTON, FRAME and IFRAME elements (where present in
    the pertinent DTDs) are specified as CDATA, and may contain any
    characters "from the document character set" (some with some additional
    restrictions).

    The ID and NAME _tokens_ apply to ID attributes, the NAME attributes of
    META elements and a number of other attributes (but not other NAME
    attributes).

    > The HTML rules for id and name tokens are:

    ^^^^^^
    >
    > "# ID and NAME tokens must begin with a letter ([A-Za-z]) and may
    > be followed by any number of letters, digits ([0-9]), hyphens
    > ("-"), underscores ("_"), colons (":"), and periods (".")."
    >
    > <URL:http://www.w3.org/TR/html4/types.html#type-cdata>
    >
    > i.e. spaces and quotes are not allowed as part of names or ids.


    They are allowed as parts of the names in a form control element's NAME
    attribute. But as they are illegal in javascript Identifiers controls
    using those characters cannot be referenced with dot notation property
    accessors, and bracket notation accessors would have to be used instead.

    Richard.
     
    Richard Cornford, Apr 17, 2005
    #6
  7. Hywel Jenkins wrote:

    > [...]
    > You're trying to have multiple values for the onclick event - you can't.
    > You need something like this:
    >
    > onClick="
    > window.close();
    > MM_validateForm('Manager Name','','R','Managers

    ^^^^^^^^^^^^^^^[1] ^^^^^^^^^[2]
    > Extension','','R','Department','','R');
    > return document.MM_returnValue;"


    [1] I recommend against using Macromedia's scripts. They are known
    to be ill-designed and therefore error-prone (later reference
    to `document.MM_returnValue' again suggests so).

    [2] I don't think this is going to work since the string is unterminated
    (unintentionally?). Try this instead:

    onclick="window.close();
    MM_validateForm('Manager Name', '', 'R', 'Manager\'s Extension',
    '', 'R', 'Department', '', 'R');
    return document.MM_returnValue;"

    But due to the nonsense of preceding window.close(), I think the OP rather
    wants something like this:

    in sender.html:

    function validateForm(formReference)
    {
    if (validationWasUnsuccessful)
    {
    return false;
    }

    return true;
    }

    <form action="receiver" ... onsubmit="return validateForm(this);" ...>
    ...
    <input type="submit" value="...">
    </form>

    in receiver:

    <body ... onload="window.close();" ...>
    ...
    </body>

    > [...]
    > There should be an apostrophe in "Managers Extension", too, but that
    > will no doubt cause you another problem.


    I don't think so , see above :)


    PointedEars
     
    Thomas 'PointedEars' Lahn, Apr 17, 2005
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    6
    Views:
    8,850
    sateeshranga
    Aug 7, 2008
  2. Iñaki Baz Castillo
    Replies:
    7
    Views:
    878
    Iñaki Baz Castillo
    Jan 12, 2010
  3. Walter Beierdonck

    Self.close() window without the dialog close?Yes/NO

    Walter Beierdonck, Apr 29, 2004, in forum: Javascript
    Replies:
    1
    Views:
    351
    Grant Wagner
    Apr 30, 2004
  4. Replies:
    3
    Views:
    413
    Chung Leong
    Jan 16, 2005
  5. Shang Wenbin

    close current window using window.close()

    Shang Wenbin, Sep 1, 2005, in forum: Javascript
    Replies:
    10
    Views:
    385
    Gérard Talbot
    Sep 2, 2005
Loading...

Share This Page