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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

onClick multiple event handler:going to a url and closing child window

Status
Not open for further replies.

Butser

Programmer
Joined
Feb 17, 2006
Messages
8
Location
GB
I would like to do two actions when an onClick event is fired: 1 = go to a url; 2 = close a window.

The problem is that I believe the url must be enclosed in double quotes whilst also double quotes must be used to enclose multiple event handler code. Hence, my borwser is reporting a syntax error (IE v6).

The code I am using is (for example):
<input type=button onClick="self.opener.location=" self.close();">

I would be very grateful for any suggestions about how to get this code to work without having to resort to an external function call.
 
Thanks for reply - I tried enclosing the url using single quotes but my browser reports an error saying "Expected ')'".
 
Sorry - replied before seeing your last post! What do you mean by "escape the inner double quotes"?
 
To escape the double quotes, simply put a backslash before them:

Code:
<input type=button onclick="self.opener.location = \"[URL unfurl="true"]http://www.oracle.com\";[/URL] self.close();">

However, unless there's something you're not telling us, the single quotes should work perfectly well:

Code:
<input type=button onclick="self.opener.location = '[URL unfurl="true"]http://www.oracle.com';[/URL] self.close();">

Dan

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Hi,

This is the exact code that I am using:

win.document.write('<input type="button" class=button value="Close Window" onClick="self.opener.location=' self.close();">')

The button is to appear in a popup window fired from the main browser window. When I press the button to fire the child window, I receive the error: "Expected ')'". If I surrond the url with double quotes and remote those surronding the event handler, all is ok but the code to close the child window does not fire.

Not sure what the problem is with using single quotes!

Also, tried using escape characters and browser raised "Invalid character" message.
 
Right - so there was a [!]lot[/!] you weren't telling us. Just goes to show - the answers you get are only as good as the information you give. Garbage in, garbage out, as they say.

Try this:

Code:
win.document.write('<input type="button" class=button value="Close Window" onClick="self.opener.location = \'[URL unfurl="true"]http://www.oracle.com\';[/URL] self.close();">');

Dan



[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Hi,

Thanks for the reply - this works great! Really appreciate your help.

What is the significance of the '\' char - why is it required when using win.document.write?
 
Butser said:
What is the significance of the '\' char - why is it required when using win.document.write?

As Dan said (in the quote below), it's used to escape them if you want to include them as part of the statement.

Dan said:
To escape the double quotes, simply put a backslash before them:



____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
In this case, the \ escapes the ' character, so it is no longer used to terminate the string. Instead, it is included in the string as a regular single quote.

Dan



[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top