Page 1 of 2 12 LastLast
Results 1 to 10 of 16

Thread: Adding onclick function within document.write tag

  1. #1
    Join Date
    Apr 2008
    Posts
    14
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Adding onclick function within document.write tag

    I am trying to use a javascript that allows a series of images to randomly show, but instead of it just activating a link in an href tag, I want it to see an onclick event which contains a javascript call from another script in the page.

    I am trying to put the following a href tag into a document.write tag and I can't seem to get the syntax right or know if it is possible to put another javascript function call into a different javascript:

    This is the tag that would rest in a lone href tag:
    <a href="#" onclick="return hs.htmlExpand(this, { contentId: 'highslide-html' } )" class="highslide"><img src="image.gif></a>

    And this is how I tried to enter the tag:

    document.write('<a href =\"' + url + '\" onclick=\"return hs.htmlExpand(this, { contentId: '+ contentId +' } )\" class='highslide'>');

    Any help would be MUCH appreciated.

  2. #2
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    Code:
    document.write('<a href="' + url + '" onclick="return hs.htmlExpand(this, { contentId: '+ contentId +' } )" class="highslide">');
    Hope this helps.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  3. #3
    Join Date
    Apr 2008
    Posts
    14
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Tried the adaption...

    Thank you for the adaption, I thought I had to put an escape character in quotes. However it is ignoring my onclick tag. The function is in a script that is being called in a .js file. I even tried putting the javascript on the page instead of in an external file and it is still ignoring it.

    Here is the entire document write of the javascript, am I doing something that is making it ignoring the onclick command?

    document.write('<a href="' + url + '" onclick="return hs.htmlExpand(this, { contentId: '+ contentId +' } )" class="highslide">');
    document.write('<img src=\"' + Graphic + '\" width=')
    document.write(width + ' height=' + height + ' ');
    document.write('border=0>');
    document.write('</a>');

    Thanks again for your help.

  4. #4
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    I just tried it out locally and it does work when I assign dummy variables to the code you posted above. This is the test page that I made up locally:

    Code:
    <html>
     <head>
      <title>Test</title>
     </head>
    <body>
    
    <script type="text/javascript">
    var url='test.html';
    var Graphic='test.gif';
    var width='100';
    var height='100';
    var contentId = 'test';
    
    
    document.write('<a href="' + url + '" onclick="return hs.htmlExpand(this, { contentId: '+ contentId +' } )" class="highslide">');
    document.write('<img src=\"' + Graphic + '\" width=')
    document.write(width + ' height=' + height + ' ');
    document.write('border=0>');
    document.write('<\/a>');
    </script>
    
    </body>
    </html>
    If you are still having issues, please post a link to your problem page.

    Hope this helps.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  5. #5
    Join Date
    Apr 2008
    Posts
    14
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Still having a problem... <cringe>

    Let me first say, thank you so much for helping. The image is coming up and it sees the url but it is still ignoring my onclick, the onclick should be pulling up a div with content like it does on my non java page.

    Login with username: jolie@designamics.com password: test

    This is the non java page with the working onclick function:

    http://www.imarentertainment.com/newsite/Home.asp

    Here is the java page with the images coming up and rotating but the onclick function being ignored (no div coming up):

    http://www.imarentertainment.com/newsite/Home_java.asp

    I have noticed that on the java page it will append the url with a # but on the non java page it will not, I don't know if the document.write is perhaps overwriting the onclick or something.

    All help is appreciate immensely of course!

  6. #6
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    The error I'm getting is that hs is not defined. The reason for this is that you have not placed the following in Home_java.asp:

    Code:
    <script type="text/javascript" src="highslide/highslide.js"></script>
    That's all it is now.

    Hope this helps.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  7. #7
    Join Date
    Apr 2008
    Posts
    14
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default missing .js file

    I put the contents of the .js file right into the document in the Home_java.asp and removed the include, but I went ahead and put it back in (the call for the .js file) but it still isn't opening the div. Ideas? Again, thank you.

  8. #8
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    Ok, let me try explaining this again. Get rid of the actual javascript code that's in the html and only use the <script type="text/javascript"> parts to include the js. That's the only issue I see because apparently you have the hs defining script after the other part which is causing errors (if that makes sense).

    Hope this helps.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  9. #9
    Join Date
    Apr 2008
    Posts
    14
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default removed other java script

    Ok I removed javascript from the actual page and have only the .js for the hs definition. That is what I had there originally, I thought maybe it wasn't pulling from the file. I have the .js script in the header and the other part in the body, but i saw you said that the hs was being defined after the other part causing errors. I tried putting the other part into a .js file too and just calling that but still no luck.

    And thank you SO much for your patience and help, once again.

  10. #10
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    Well, now the error I'm getting is highslide not defined. Thing about that error is that I can't find any reference to it and that makes no sense. I'll keep looking to see if I can figure it out, but it might take a little while.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •