Solved

Problem with JavaScript doScroll

Posted on 2004-10-22
726 Views
Last Modified: 2012-06-22
On a web page, I have a textarea box, and a checkbox.  The javascript code is supposed to automatically scroll the textarea contents (which are dynamically updated by a vbscript), however I want the option to stop scrolling automatically once the checkbox is checked.  It all works just fine except when I click on the check box the IE window locks up..

<SCRIPT>
var iTimer;
function timeIt()
{
      iTimer = setInterval("scrollIt()", 10);
}

function scrollIt(){
do{
      document.form.wstatus.doScroll("down");
}while (document.form.wdone.checked == false)
}

</SCRIPT>
0
Question by:jb6884
    5 Comments
     
    LVL 3

    Expert Comment

    by:k-do
    The problem with your function is that it is in a perpetual loop.

    iTimer = setInterval("scrollIt()", 10);

    The above line sets up a timer which executes the *function* scrollIt() every 10 ms.  Since you have used a do...while statement in your function, the function continues to loop without any delay.

    You need to change your scrollIt() function to the following:

    function scrollIt(){
    if (document.form1.wdone.checked == false)
         document.form1.wstatus.doScroll("down");
    }

    Hope this helps,

    Keith

    0
     
    LVL 3

    Accepted Solution

    by:
    Check that... I modified the code when I was testing the solution... the correct code (based on what you posted) will be:

    function scrollIt(){
    if (document.form.wdone.checked == false)
         document.form.wstatus.doScroll("down");
    }
    0
     
    LVL 3

    Expert Comment

    by:xakem
    what do you think about the following:

    <html>
    <head>
    <script>
    function stopScrl()
    {
          c = document.getElementById('chkbx').checked
          s = document.getElementById('scrl')
          
          if (c)
                s.stop()
          else
                s.start()
    }
    </script>
    </head>
    <body>
    <marquee id="scrl" scrollAmount="1" direction="down" style="border: solid black 2px; width: 200px"><center>scroll scroll scroll</center></marquee><input id="chkbx" type="checkbox" onClick="stopScrl()">Click
    </body>
    </html>

     ? this is one of the ways
    0
     
    LVL 3

    Expert Comment

    by:k-do
    xakem -

    I don't think that your solution addresses the question... jb6884 specifically stated that his web page uses a textarea box and a check box.  Your solution uses a marquee.

    It provides an alternative method of accomplishing the task, but there could be other reasons that jb6884 needs to specifically use a textarea box.

    Keith
    0
     
    LVL 3

    Expert Comment

    by:xakem
    no problem Keith, we r free to suggest here, aren't we ;)
    i will be more accurate next time, thx for reminding.
    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    The first time you look at a web page and its source code, you are probably a little intimidated by the use of symbols and jargon that really looks foreign to you. You might not even know where to start to begin learning what it all means. That’…
    Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
    The viewer will learn how to dynamically set the form action using jQuery.
    The viewer will learn how to count occurrences of each item in an array.

    933 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now