Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Pause A Function in javascript

Posted on 1999-07-03
13
Medium Priority
?
3,269 Views
Last Modified: 2008-03-03
I have a function in javascript like below:

<script language="JavaScript">
function sendit(){
document.form1.submit();
document.form2.submit();
}
</script>

I would like to pause the function between the two submit
statments. How do I do this?
0
Comment
Question by:timothy1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
13 Comments
 
LVL 10

Accepted Solution

by:
viktornet earned 200 total points
ID: 1288635
try this.,,,,


<html>
<head>
<title>TEST</title>
<script language="JavaScript">
  var i = 0
  var secs = 3
  function test()
  {
    alert("TEST")
  }
  function submit1()
  {
    if (i++ == secs) test()
    setTimeout("submit1()", 1000)
  }
</script>
</head>

<body bgColor = "#AAAAAA">
  <script language="JavaScript">
    submit1(3)
  </script>
</body>
</html>

..-=ViKtOr=-..
0
 

Author Comment

by:timothy1
ID: 1288636
Nope doesn't work
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1288637
it does on my computer.... I tried it and it works just fine.... the code simply displays the TEST message box after 3 seconds.... What isn't working??
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:timothy1
ID: 1288638
Look, I don't want to display anything. I want to have the function I sent in the original question to pause and then restart.
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1288639
i know you don wanna display anything... I was just showed you how to do it,,, that was a test.... can you show me your code so I can see how you've structured it an all? 10x

-vik-
0
 

Author Comment

by:timothy1
ID: 1288640
Huh, I did there are two Forms on the docuement one named form1 and the other is named form2. When the user clicks the submit button the onclick="sendit();" calls the javascript I already have. Now I want to paused the function for ten secounds after the first:

document.form1.submit();

and this have it resume and

document.form2.submit();

now it looks like your submit() function would be where I put the first document.form1.submit();

and your test() is where i could put my document.form2.submit();

but you go this thing to start when the window is loaded or refreshed how do I get it to start on my onclick="sendit()"

and what it the second script for?
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1288641
try this....

............

      <script language="JavaScript">
        var i = 0
        var secs = 3

        function submit2()
        {
          if (i++ == secs)  document.form2.submit();
          setTimeout("submit2()", 1000)
        }
          function sendit()
           {
               document.form1.submit();
                submit2();
            }
      </script>
      </head>

      <body>
          .......
           onclick="sendit();"
           ........
      </body>
      </html>

tell me if this works or not for you....

..-=ViKtOr=-..
0
 
LVL 33

Expert Comment

by:knightEknight
ID: 1288642
Your function:

<script language="JavaScript">
function sendit(){
document.form1.submit();
document.form2.submit();
}
</script>

... will not work because as soon as the first form is submitted, the server loads a new page into the browser and the function no longer exists, therefore the second submit() call never occurs.  There are two ways to work around this.  

First of all, you can put form1 and form2 in different frames, and then have the onSubmit handler of each form call the submit() method of the other like this:

<FORM name='form1' onSubmit='parent.frame2.form2.submit();return(true)'>

The second option depends on what your forms look like...
Are form1 and form2 identical forms (except for the action clause)?

0
 
LVL 1

Expert Comment

by:mSH
ID: 1288643
I agree with knightEknight: "as soon as the first form is submitted, the server loads a new page into the browser and the function no longer exists"
0
 

Author Comment

by:timothy1
ID: 1288644
Well your both wrong! It does work because the first form isn't loading another page.
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1288645
so it works now, right?
0
 

Author Comment

by:timothy1
ID: 1288646
Yep I had to add a third routine to keep it from looping forever
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1288647
k , cool :)
0

Featured Post

Build and deliver software with DevOps

A digital transformation requires faster time to market, shorter software development lifecycles, and the ability to adapt rapidly to changing customer demands. DevOps provides the solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

721 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