Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-30-2013, 12:30 AM   PM User | #1
yemista
New to the CF scene

 
Join Date: Jan 2013
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
yemista is an unknown quantity at this point
trouble with quotes

I have this line of javascript:

Code:
throne.innerHTML =  "<a href=home.php onclick='document.body.removeChild(document.getElementById("+"'throne'"+"));return false';>HEllo</a>";
the problem is its coming out as

Code:
<a href="home.php" onclick="document.body.removeChild(document.getElementById('throne'));return false;">HEllo</a>
i dont understand why javascript is not using the quotes as id like them to be used. ideally, i want this:

Code:
<a href="home.php" onclick="document.body.removeChild(document.getElementById(" throne'));return="" false';="">HEllo</a>
yemista is offline   Reply With Quote
Old 01-30-2013, 02:24 AM   PM User | #2
jmrker
Senior Coder

 
jmrker's Avatar
 
Join Date: Aug 2006
Location: FL
Posts: 2,764
Thanks: 29
Thanked 453 Times in 447 Posts
jmrker will become famous soon enough
Use the escape character, '\',to specify which nested quote is to be referenced as it actually intended. It all has to do with nesting of the quotes as you have written it.
jmrker is online now   Reply With Quote
Old 01-30-2013, 03:06 AM   PM User | #3
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,210
Thanks: 59
Thanked 3,996 Times in 3,965 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
What JMrkr said. BUT...

What is WRONG with this:
Code:
<a href="home.php"
 onclick="document.body.removeChild(document.getElementById('throne'));return false;"
>Hello</a>
That's perfectly legal and correct JavaScript. Though I can't for the life of me see how you got it from the code you claimed you used. For starters, what put the "..." around home.php??

Whereas this, that you say you want, is totally bogus:
Code:
<a href="home.php" 
onclick="document.body.removeChild(document.getElementById(" throne'));return="" false';=""
>HEllo</a>
It doesn't even make sense. You can't use return= anything.

Are you trying to put in the *VALUE* of the variable throne ??? Or, more likely, are you trying to use the ID of the DOM object referenced by your throne variable??

In that case:
Code:
throne.innerHTML =  
    '<a href="home.php" onclick="document.body.removeChild(document.getElementById(\''
           + throne.id +'\'));return false';">HEllo</a>';
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is online now   Reply With Quote
Old 01-30-2013, 03:07 AM   PM User | #4
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,210
Thanks: 59
Thanked 3,996 Times in 3,965 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
I *have* to ask: Why do you use href="home.php" when you are going to use return false to suppress the action of the <a> tag, anyway? Why not just href="#" ??
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is online now   Reply With Quote
Old 01-30-2013, 06:20 AM   PM User | #5
felgall
Master Coder

 
felgall's Avatar
 
Join Date: Sep 2005
Location: Sydney, Australia
Posts: 5,454
Thanks: 0
Thanked 498 Times in 490 Posts
felgall is a jewel in the roughfelgall is a jewel in the roughfelgall is a jewel in the rough
Quote:
Originally Posted by Old Pedant View Post
I *have* to ask: Why do you use href="home.php" when you are going to use return false to suppress the action of the <a> tag, anyway? Why not just href="#" ??
You don't even need to include the href= in the <a> tag in situations like this. Then once you've dropped that you can also drop the return false as then there is no default to disable.
__________________
Stephen
Learn Modern JavaScript - http://javascriptexample.net/
Helping others to solve their computer problem at http://www.felgall.com/
felgall is online now   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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

Forum Jump


All times are GMT +1. The time now is 03:32 AM.


Advertisement
Log in to turn off these ads.