Page view counter

Help with javascript

Last post 11-19-2008 9:32 AM by NC01. 5 replies.

Sort Posts:

  • Help with javascript

    11-17-2008, 6:44 AM
    • Loading...
    • silver_line
    • Joined on 11-17-2008, 11:30 AM
    • Posts 25
    • Points 6

    Hi,

    I wrote a javscript to move an image with interval with a single click. All the images move perfectly. But the problem I am seeing is

    1) I can only move one image at a time. Not sure why I am being restricted. In aspx, I have the same function being called each with different Id's.

     2) When I go to another page and come back to this page, all the javascript image moving is lost.

     

    Please help. Attached is source code. 

     

    function AnimateImage(ImgId)

    {

    if (flag==0)

    {

    //clearInterval(ImgTimer);

    ImgId_tmp = ImgId;

    document.getElementById(
    'Enc'+ImgId+'_7000').style.left = "440px";

    TopOrig = document.getElementById('Enc'+ImgId+'_7000').style.pixelTop;

    //alert("value is", TopOrig);

    ImgTimer = setInterval("MoveImg(ImgId_tmp)", 20);

    }

    }

    function MoveImg(ImgId)

    {

    ImgId_tmp = ImgId;

    document.getElementById(
    'Enc'+ImgId+'_7000').style.pixelTop -= 2;

    //document.write("HEllo");//,DDL_Move.Text);

    //var ddlval = $get('<%=DDL_Move %>').SelectedIndex;

    var ddl = document.getElementById("DDL_Move");

    var ddlval = ddl.options[ddl.selectedIndex].value;

    //alert ("Value is ", +Val);

    //document.write("<H",DDL_Move.SelectedValue,">","</H",headLevel,">");

    if (document.getElementById('Enc'+ImgId+'_7000').style.pixelTop < (TopOrig/6-ddlval*55/6))

    {

    clearInterval(ImgTimer);

    ImgTimer = setInterval(
    "MoveImgLeft(ImgId_tmp)", 20);

    //document.getElementById("Enc2_7000").style.left = "275px";

    flag=1;

    }

    }

    function MoveImgLeft(ImgId)

    {

    document.getElementById(
    'Enc'+ImgId+'_7000').style.pixelLeft -= 2;

    if (document.getElementById('Enc'+ImgId+'_7000').style.pixelLeft < 275)//ddlval*55-Val)

    {

    clearInterval(ImgTimer);

    //ImgTimer = setInterval("MoveImgLeft()", 20);

    // document.getElementById("Enc2_7000").style.left = "275px";

    flag=1;

    }

    }

  • Re: Help with javascript

    11-17-2008, 8:06 AM
    • Loading...
    • NC01
    • Joined on 08-26-2005, 7:33 PM
    • Posts 13,275
    • Points 71,391

    silver_line:

    1) I can only move one image at a time. Not sure why I am being restricted. In aspx, I have the same function being called each with different Id's.

    The AnimateImage function only works when a variable named "flag" is 0 and you set it to 1 on the first call to MoveImg or MoveImgLeft and I see no where that you set it back to 0.

    silver_line:

    2) When I go to another page and come back to this page, all the javascript image moving is lost.

    Of course. Web pages don't remember what was done to them before! Each rendering is like new. You would need to save the positions some how and re-set them on page load.

    NC...

  • Re: Help with javascript

    11-18-2008, 8:11 PM
    • Loading...
    • silver_line
    • Joined on 11-17-2008, 11:30 AM
    • Posts 25
    • Points 6

     

    Thanks a lot.

     Could you also give me some suggestions for the following

    1) I have to select some images within a block based on some drop down selectins. I have done all the coding in c# and works great. The way I did was to have the images as invisible on aspx page and made them visible based on the selection criteria. The block i call it as enclosure.

    The new problem i am working on is having these images displayed on the first page with much smaller resolution. Other words, the entire enclosure should be displayed on the first page with smaller resolution.The image should also move based on other selection rules on the first page. I am thinking of moving the enclosure on the first page using java script.

    Not sure of how to do the first part, where display the images on second page on first page. This is not a single image, these are a collection of images based on some specific selection (almost like a formula).

     

    Please suggest me some good approaches.

     

    Thanks,

  • Re: Help with javascript

    11-19-2008, 8:29 AM
    • Loading...
    • NC01
    • Joined on 08-26-2005, 7:33 PM
    • Posts 13,275
    • Points 71,391

    From what you've posted, I have no idea how to help you on that. Sounds more like a design issue rather than a code issue though.

    NC...

  • Re: Help with javascript

    11-19-2008, 9:27 AM
    • Loading...
    • silver_line
    • Joined on 11-17-2008, 11:30 AM
    • Posts 25
    • Points 6

    Can Javascript on webpage coexist on  the same page with aspx page with autopost back as true?. The reason for this is, I have a java script running on client to move images on mouse click of image and selection of a dropdown list with autopost back as true, if this is not possible, is  the only possible alternative is to code in two different pages(pass around values in two different pages)?

    If(!post_back) can I use this and put all the code inside? This still not solve my problem because aspx page needs to have autopost back as true

  • Re: Help with javascript

    11-19-2008, 9:32 AM
    Answer
    • Loading...
    • NC01
    • Joined on 08-26-2005, 7:33 PM
    • Posts 13,275
    • Points 71,391

    As soon as the PostBack happens no more code is executed, since the page is submitted at that moment. I'd suggest setting the AutoPostBack property on the DDL to false.

    NC...

     

Page 1 of 1 (6 items)