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

Discussion in 'HTML' started by Spartanicus, Oct 7, 2005.

  1. Spartanicus

    Spartanicus Guest

    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.

    --
    Spartanicus
     
    Spartanicus, Oct 7, 2005
    #1
    1. Advertising

  2. Spartanicus

    Dylan Parry Guest

    Using a pointed stick and pebbles, Spartanicus scraped:

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


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

    --
    Dylan Parry
    http://electricfreedom.org -- Where the Music Progressively Rocks!
     
    Dylan Parry, Oct 7, 2005
    #2
    1. Advertising

  3. Spartanicus

    rf Guest

    Dylan Parry wrote:

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

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


    or perhaps:

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

    --
    Cheers
    Richard.
     
    rf, Oct 7, 2005
    #3
  4. Spartanicus

    Dylan Parry Guest

    Using a pointed stick and pebbles, rf scraped:

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

    >
    > 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.

    --
    Dylan Parry
    http://webpageworkshop.co.uk -- FREE Web tutorials and references
     
    Dylan Parry, Oct 7, 2005
    #4
  5. Spartanicus

    rf Guest

    Dylan Parry wrote:

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

    >>
    >> 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.


    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 :)

    --
    Cheers
    Richard.
     
    rf, Oct 7, 2005
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Abdul Mohsin
    Replies:
    1
    Views:
    284
  2. Angus
    Replies:
    2
    Views:
    146
    Darko
    Apr 19, 2007
  3. AzamSharp
    Replies:
    2
    Views:
    192
  4. soni2926
    Replies:
    4
    Views:
    119
    William James
    Nov 21, 2008
  5. Frank Peterson
    Replies:
    9
    Views:
    242
    David Mark
    Jun 28, 2009
Loading...

Share This Page