SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    Dec 2005
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Passing an object in Javascript

    I'm getting some cruddy errors when I try to pass an object to another function.

    Here's the code: (or the crit parts)
    //function CURRENT
    //cluster is an object

    html += '<tr><td colspan="2"><a href="#" onClick="postPrev(cluster)">Previous</a>';

    //end function CURRENT

    //postPrev function start
    function postPrev ( cluster )
    {
    . . .
    }

    whenever I do this, I get a "syntax error" that says:
    postPrev([object Object])
    is not syntactically correct.

    I believe it is expecting/passing cluster as a string instead of an object - how do I fix this?

  2. #2
    SitePoint Member
    Join Date
    Aug 2006
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Create you a and give it an id. The do document.getElementById(ID).onload = function(){ postPrev(cluster)};

    This should do the trick.

  3. #3
    SitePoint Member
    Join Date
    Dec 2005
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Where do I put the document.getElementbyId(ID).onload function?

  4. #4
    SitePoint Member
    Join Date
    Dec 2005
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    So I have this string html and I want to be able to keep going to the next record (div id="mainText"). However, the problem right now is that I can only go to the next record only once. I pretty much need to be able to keep clicking the next link and then the program will keep displaying the next "mainText".

    html += '<tr><td colspan="2"><a href="#" onClick="document.getElementById(\'mainText\').innerHTML= \'' + cluster.markers[n++].title + '\'">Next</a>

  5. #5
    SitePoint Member
    Join Date
    Aug 2006
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry. Onclick. put that in just after adding the a tag to the page.


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
  •