Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Close Window Function

Reply
Thread Tools

Close Window Function

 
 
clequieu@nuvell.com
Guest
Posts: n/a
 
      04-13-2005
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

 
Reply With Quote
 
 
 
 
kaeli
Guest
Posts: n/a
 
      04-13-2005
In article <(E-Mail Removed). com>,
http://www.velocityreviews.com/forums/(E-Mail Removed) 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

 
Reply With Quote
 
 
 
 
Hywel Jenkins
Guest
Posts: n/a
 
      04-13-2005
In article <(E-Mail Removed). com>,
(E-Mail Removed) 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
 
Reply With Quote
 
RobG
Guest
Posts: n/a
 
      04-14-2005
Hywel Jenkins wrote:
> In article <(E-Mail Removed). com>,
> (E-Mail Removed) 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
 
Reply With Quote
 
RobB
Guest
Posts: n/a
 
      04-14-2005
(E-Mail Removed) 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">

 
Reply With Quote
 
Richard Cornford
Guest
Posts: n/a
 
      04-17-2005
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.


 
Reply With Quote
 
Thomas 'PointedEars' Lahn
Guest
Posts: n/a
 
      04-17-2005
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to close a TCP socket? (TCPSocket#close doesn't close it) IƱaki Baz Castillo Ruby 7 01-12-2010 01:32 PM
close all child windows when close the main window jrefactors@hotmail.com HTML 6 08-07-2008 09:10 AM
close current window using window.close() Shang Wenbin Javascript 10 09-02-2005 12:16 AM
close all child windows when close the main window jrefactors@hotmail.com Javascript 3 01-16-2005 10:06 PM
Self.close() window without the dialog close?Yes/NO Walter Beierdonck Javascript 1 04-30-2004 02:48 PM



Advertisments