loading divs dynamically -- how to detect which one loaded currently..

Discussion in 'Javascript' started by maya, Jan 25, 2007.

  1. maya

    maya Guest

    I'm using a function like this to load divs dynamically (and hide
    current one..)

    function get_img(curr_img,curr_nav,new_img,new_nav2) {
    var img_top = eval('document.getElementById(' + "curr_img" + ')');
    var img_new = eval('document.getElementById(' + "new_img" + ')');
    var nav_top = eval('document.getElementById(' + "curr_nav" + ')');
    var nav_new = eval('document.getElementById(' + "new_nav" + ')');
    img_top.style.visibility = "hidden";
    img_new.style.visibility = "visible";
    nav_top.style.visibility = "hidden";
    nav_new.style.visibility = "visible";
    curr_img = new_img;
    curr_nav = new_nav;
    }

    problem I always run into in situations like this is I can't tell which
    one is currently loaded.. how do you detect which div is currently loaded?

    this is in JSP, divs generated with loops...

    for (int i = 0; i < photos.length; i++) {
    %>
    <div id="nav<%=photos%>">

    etc...

    thank you.............
    maya, Jan 25, 2007
    #1
    1. Advertising

  2. maya wrote:
    > I'm using a function like this to load divs dynamically (and hide
    > current one..)
    >
    > function get_img(curr_img,curr_nav,new_img,new_nav2) {
    > var img_top = eval('document.getElementById(' + "curr_img" + ')');


    Why are you evaluating instead of just doing

    var img_top = document.getElementById(cur_img);

    ??????????

    > var img_new = eval('document.getElementById(' + "new_img" + ')');
    > var nav_top = eval('document.getElementById(' + "curr_nav" + ')');
    > var nav_new = eval('document.getElementById(' + "new_nav" + ')');
    > img_top.style.visibility = "hidden";
    > img_new.style.visibility = "visible";
    > nav_top.style.visibility = "hidden";
    > nav_new.style.visibility = "visible";
    > curr_img = new_img;
    > curr_nav = new_nav;
    > }
    >
    > problem I always run into in situations like this is I can't tell which
    > one is currently loaded.. how do you detect which div is currently loaded?



    Not enough information here to have any clue what you mean.


    > this is in JSP, divs generated with loops...
    >
    > for (int i = 0; i < photos.length; i++) {
    > %>
    > <div id="nav<%=photos%>">
    >
    > etc...
    >
    > thank you.............
    >
    TheBagbournes, Jan 27, 2007
    #2
    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. rich
    Replies:
    0
    Views:
    720
  2. Replies:
    0
    Views:
    719
  3. Alex
    Replies:
    1
    Views:
    94
  4. mark4asp
    Replies:
    1
    Views:
    201
    Gary Hasler
    Apr 4, 2007
  5. maya
    Replies:
    4
    Views:
    240
Loading...

Share This Page