Javascript: is it possible to pass a parameter to a function inside a document write?

S

Spartanicus

Is it possible to pass a parameter to a function that is written using a
document.write?:

document.write('<span onclick="myfunction(parameter)"><span>');

Using single quotes prematurely delimits the document.write, using
double quotes prematurely delimits the attribute value.
 
D

Dylan Parry

Using a pointed stick and pebbles, Spartanicus scraped:
document.write('<span onclick="myfunction(parameter)"><span>');

document.write('<span onclick="myfunction(' + parameter + ')"></span>');
 
R

rf

Dylan said:
Using a pointed stick and pebbles, Spartanicus scraped:


document.write('<span onclick="myfunction(' + parameter + ')"></span>');

or perhaps:

document.write('<span onclick="myfunction(\"parameter\")"><span>');
 
D

Dylan Parry

Using a pointed stick and pebbles, rf scraped:
or perhaps:

document.write('<span onclick="myfunction(\"parameter\")"><span>');

Hmm, I was reading the OP as something else, ie. how to dynamically add
a parameter value using JavaScript to write the actual value based on a
variable named "parameter" which needed to be inserted into the function
call.
 
R

rf

Dylan said:
Using a pointed stick and pebbles, rf scraped:


Hmm, I was reading the OP as something else, ie. how to dynamically add
a parameter value using JavaScript to write the actual value based on a
variable named "parameter" which needed to be inserted into the function
call.

So I deduced. I took it the other way, as in eg
onclick="alert(\"I have been clicked\")"

A "real world" example by the OP may have been a better idea :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top