SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Member
    Join Date
    Dec 2003
    Location
    Canada
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    changing div contents dynamically

    Hi


    Is there a way to change the contents of a div block dynamically?
    Or should I use iframe instead?

    Thanks

  2. #2
    I'll take mine raw silver trophy MikeFoster's Avatar
    Join Date
    Dec 2002
    Location
    Alabama, USA
    Posts
    2,560
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Are you talking about loading an html page into the DIV, or just assigning a string of html to it?

  3. #3
    SitePoint Zealot tss68nl's Avatar
    Join Date
    Nov 2002
    Location
    Netherlands
    Posts
    165
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Lol...mike means...if you are going to load a full html page in it, use iframe, if you just want to assign some content to a container, then set oDiv.innerHTML = "something". oDiv here is the name/id of your div, or a variable that got the correct div assigned to it in an earlier stage.

  4. #4
    ☆★☆★ silver trophy vgarcia's Avatar
    Join Date
    Jan 2002
    Location
    in transition
    Posts
    21,235
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by tss68nl
    Lol...mike means...if you are going to load a full html page in it, use iframe, if you just want to assign some content to a container, then set oDiv.innerHTML = "something". oDiv here is the name/id of your div, or a variable that got the correct div assigned to it in an earlier stage.
    Remember that innerHTML doesn't work in Opera .

  5. #5
    I'll take mine raw silver trophy MikeFoster's Avatar
    Join Date
    Dec 2002
    Location
    Alabama, USA
    Posts
    2,560
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes, tss68nl explained it better

    also... innerHTML works in Opera7 but not previous versions.

    Thanks tss68nl and Vinnie

  6. #6
    SitePoint Member
    Join Date
    Dec 2003
    Location
    Canada
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks. Actually I wanted to load a table of data from database. Every time when user clicks a button, new queried data will appear in the div block.

  7. #7
    ☆★☆★ silver trophy vgarcia's Avatar
    Join Date
    Jan 2002
    Location
    in transition
    Posts
    21,235
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by students
    Thanks. Actually I wanted to load a table of data from database. Every time when user clicks a button, new queried data will appear in the div block.
    That's probably better left to a server-side script in that case.

  8. #8
    I'll take mine raw silver trophy MikeFoster's Avatar
    Join Date
    Dec 2002
    Location
    Alabama, USA
    Posts
    2,560
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Vinnie's right. The only alternative I know of is remote scripting.

  9. #9
    SitePoint Addict
    Join Date
    Sep 2003
    Location
    Kingston
    Posts
    246
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Actually an iframe would be the easiest thing for this. Just set the target of the form with the button you're clicking to the iframe name.

  10. #10
    SitePoint Zealot tss68nl's Avatar
    Join Date
    Nov 2002
    Location
    Netherlands
    Posts
    165
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ah, good old no-refresh stuff

    Well..my own solution to this stuff is generally use of both iframes and divs. You can set up a central way to asynchronously retrieve data with javascript by making a function that will accept an url to retrieve, then call a callback function.

    You set a hidden iframe up somewhere in the page, and just let the function set the url of the iframe, containing the name of the function to call. The server side script then generates the returning page, including a javascript that will call the callback function after the onLoad event of the body.

    The callback function in his turn, will read the contents of the iframe, and do something useful with it (for example copy the results to some div on the page in proper formatting). Works in about any browser (since a variant is also available in the form of a 0 pixel wide frame in a frameset), as long as the browser supports basic javascript support.

    The benefit of going about it this way is you have a handy component that will bring this functionality to any site you copy it to, ready to use. Also div's are a bit more flexible than iframes in my opinion, actually...I myself loath using visible iframes. Making it even more portable you might consider cutting out the need for the info page to contain javascript, and just let the calling function check wether a new page has been loaded into the iframe yet. (Consider setting the iframes content to 'loading' or something)


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
  •