473,386 Members | 1,647 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

document.write problems

hi there,

I am trying to use document.write to write an event handler, but all
I get is syntax errors..(this is all on one line)

document.write('<a href="#" onClick="jkpopimage("'+imageFileName+'",
"'+imageText+'"); return false"><img src="'+thumbFileName+'" width="50"
height="50" border="1"></a>');

The actual error is the first occurance of >... anyone shed any light on
this?

Thanks,

Russell
Jul 20 '05 #1
5 5134
Russell Quinn wrote on 24 Nov 2003:
hi there,

I am trying to use document.write to write an event handler, but
all I get is syntax errors..(this is all on one line)

document.write('<a href="#"
onClick="jkpopimage("'+imageFileName+'", "'+imageText+'");
return false"><img src="'+thumbFileName+'" width="50"
height="50" border="1"></a>');

The actual error is the first occurance of >... anyone shed any
light on this?


The more likely error is that you didn't escape the forward slash:

'...</a>'); should be '...<\/a>');

Other than that, the statement is fine. The only other possible
problem would be that the jkpopimage() function isn't defined, but
you'll have to check that.

Mike

--
Michael Winter
M.******@blueyonder.co.uk.invalid (remove ".invalid" to reply)
Jul 20 '05 #2
"Russell Quinn" <russell.quinn@*PLEASENOSPAM*blueyonder.co.uk> writes:
I am trying to use document.write to write an event handler, but all
I get is syntax errors..(this is all on one line)
When do you get syntax errors? When calling document.write, or when
calling the event handler?

What, *exactly*, are the contents of imageFileName and imageText?
The actual error is the first occurance of >... anyone shed any light on
this?


What is the error message?
Which browser do you use?
(And can we see the rest of the page?)

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #3
VK
Did not use this trick for a while, but I remember some security
limitations on JavaScript via write() method. In 4th versions it did no
work (was not forwarded to the script interpreter), that was the time I
dropped it, I'm wondering about now.
Jul 20 '05 #4
> document.write('<a href="#" onClick="jkpopimage("'+imageFileName+'",
"'+imageText+'"); return false"><img src="'+thumbFileName+'" width="50"
height="50" border="1"></a>');

The actual error is the first occurance of >... anyone shed any light on
this?


I had a play and found that IE6 reported a syntax error on running the
script but Mozilla and Opera were happy. The location of the error wasn't
usefully reported. However what IE really seemed to be unhappy about that
the code actually wrote (with invented contents of the variables)...

<a href="#" onClick="jkpopimage("filename.jpg","some text"); return false">

....and you can see that the onClick code is delimited by double quotes but
also has them in the contents. Changing the delimiting quotes to \' made IE
happy.


Jul 20 '05 #5
...and you can see that the onClick code is delimited by double quotes but
also has them in the contents. Changing the delimiting quotes to \' made IE
happy.


thanks for all the comments, i eventually worked it out later... it was the above
suggestion that I had the function parameters delimited by the same method
as the onClick handler :o(
Jul 20 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: James Marshall | last post by:
I'm writing a library where I want to override document.write(), but for all document objects; thus, I want to put it in the prototype. I tried Document.prototype.write= my_doc_write ; but it...
2
by: Bruce | last post by:
I have sucessfully used document.write in a new window, but I now wish to write to an already open & framed window. How do I do it. Please show example, as I have trouble getting my head around JS....
13
by: Stumped and Confused | last post by:
Hello, I really, really, need some help here - I've spent hours trying to find a solution. In a nutshell, I'm trying to have a user input a value in form's textfield. The value should then be...
136
by: Matt Kruse | last post by:
http://www.JavascriptToolbox.com/bestpractices/ I started writing this up as a guide for some people who were looking for general tips on how to do things the 'right way' with Javascript. Their...
2
by: robert.waters | last post by:
Hello, I am dynamically editing the contents of a page and using document.write() to reload the new, edited content. However, on the new page, any calls to functions located in external .js...
7
by: Andrea | last post by:
Hi there - I'm hoping someone can help me; I've been struggling with this for a few days! :-) I have a webpage that is comprised of many forms containing questions. As the user answers one...
11
by: Michael Powe | last post by:
How can I make an XHTML-compliant form of an expression in this format: document.write("<scr"+"ipt type='text/javascript' src='path/to/file.js'>"+"</scr"+"ipt>"); this turns out to be a...
10
by: webEater | last post by:
Hello, I try the following in Firefox and other modern browsers: window.addEventListener('load', function() { document.title = CSS.getClass('fontSize'); var div = document.createElement('div');...
5
by: SuneR | last post by:
Hi, I am having problems figuring out how to make Firefox behave, and output the HTML I want it to output. The thing I want done is actually quite simple. I have a <labeltag, and inside it, I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.