Forum Moderators: open

Message Too Old, No Replies

innerHTML and link that calls javascript

         

too much information

8:14 am on Mar 20, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm having trouble with innerHTML because I am trying to replace a block of HTML with a new block that includes a link that calls a javascript. I think the problem is with the single quotes included in the new link code.

Here is what I'm doing:
document.getElementById('proofBox').innerHTML = '<a href="javascript:loadContent('someFile.php?dh='+document.getElementById('myDIV').offsetHeight+'&dw='+document.getElementById('myDIV').offsetWidth);">Link Text</a>';

Is there some safe way to escape some of those quotes to get this to work?

lavazza

9:05 am on Mar 20, 2008 (gmt 0)

10+ Year Member



to escape a character, use the \ slash

to see what you're doing, using indentation (aka metrosexual programming [google.com])

It seems that you have a superfluous );

What is &dw?

If you want an HTML ampersand, it ought to be &amp;dw=

try

document.getElementById('proofBox').innerHTML = '' 
+'<a href= "javascript:loadContent(\'someFile.php?dh='
+ document.getElementById('myDIV').offsetHeight
+ '&dw='
+ document.getElementById('myDIV').offsetWidth
+ '\'">'
+'Link Text<\/a>';

too much information

4:25 pm on Mar 20, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



it's a call to a php script, the &dw is part of the querystring that holds the width of the 'myDIV'

Ok, the metrosexual programming thing is pretty funny. I had to look it up, I thought I was being insulted! :)

Actually the extra ); was the end of the loadContent( call, so it is needed. I'll give the \ slash a try, thanks for the help.