javascript >> Please help -- How to run script several times within one document

by ThunStorm » Wed, 15 Feb 2006 23:22:18 GMT

Please help!!! I have a script that I am able to run one time. After
adding a second phase to run the script the script bugs out. How can I
get the script to run several times and pull the same data?

Here is what I am using:

<head>
<title>Untitled</title>
<style type="text/css">
.dropcontent{
width: 300px;
height: 140px;
display:block;
}
</style>

<script type="text/javascript">

if (document.getElementById){
document.write('<style type="text/css">\n')
document.write('.dropcontent{display:none;}\n')
document.write('</style>\n')
}

function contractall(){
if (document.getElementById){
var inc=0
while (document.getElementById("dropmsg"+inc)){
document.getElementById("dropmsg"+inc).style.display="none"
inc++
}
}
}

function expandone(){
if (document.getElementById){
var selectedItem=document.dropmsgform.dropmsgoption.selectedIndex
contractall()
document.getElementById("dropmsg"+selectedItem).style.display="block"
}
}

if (window.addEventListener)
window.addEventListener("load", expandone, false)
else if (window.attachEvent)
window.attachEvent("onload", expandone)

</script>
================
Here is the body:
<form name="dropmsgform">

<select name="dropmsgoption" size="1" style="width:175"
onChange="expandone()">
<OPTION>Select Team
<OPTION>#1 Lucky Strikes
<OPTION>#2 Morn-D-Lites
<OPTION>#3 Pin-Up's
<OPTION>#4 Pin Pals
<OPTION>#5 Dreamers
<OPTION>#6 Ups + Downs
<OPTION>#7 Alley Cats
<OPTION>#8 Blind
</SELECT>
    
<INPUT TYPE=text NAME=ihg1 SIZE=2 MAXLENGTH=4>

<div id="dropmsg0" class="dropcontent">
???
</div>

<div id="dropmsg1" class="dropcontent">
Karen L.
<br>
Marlene T.
<br>
Joyce A.
<br>
Mickey Z.
</div>


Similar Threads

1. Use the same java script several different times in one document in a table

I am a beginner and trying to figure this out? How can I get another
version of the javascript to appear in another table cell using the
same script? I have to use the same script 8 different times with the
same team names?  Thank you in advance.

Here is the code:
<html>
<head>
	<title>Untitled</title>
	<style type="text/css">
.dropcontent{
width: 300px;
height: 140px;
background-color: #fa006b;
display:block;
}
</style>

<script type="text/javascript">

if (document.getElementById){
document.write('<style type="text/css">\n')
document.write('.dropcontent{display:none;}\n')
document.write('</style>\n')
}

function contractall(){
if (document.getElementById){
var inc=0
while (document.getElementById("dropmsg"+inc)){
document.getElementById("dropmsg"+inc).style.display="none"
inc++
}
}
}

function expandone(){
if (document.getElementById){
var selectedItem=document.dropmsgform.dropmsgoption.selectedIndex
contractall()
document.getElementById("dropmsg"+selectedItem).style.display="block"
}
}

if (window.addEventListener)
window.addEventListener("load", expandone, false)
else if (window.attachEvent)
window.attachEvent("onload", expandone)

</script>
</head>

<body>
<Table border="1">
<tr>

<td>
<form name="dropmsgform">

		<select name="dropmsgoption" size="1" style="width:175"
onChange="expandone()">
    	<OPTION>Select Team
		<OPTION>#1  Lucky Strikes
		<OPTION>#2  Morn-D-Lites
		<OPTION>#3  Pin-Up's
		<OPTION>#4  Pin Pals
		<OPTION>#5  Dreamers
		<OPTION>#6  Ups + Downs
		<OPTION>#7  Alley Cats
		<OPTION>#8  Blind
		</SELECT>
		     
		<INPUT TYPE=text NAME=ihg1 SIZE=2 MAXLENGTH=4>

<div id="dropmsg0" class="dropcontent">
???
</div>

<div id="dropmsg1" class="dropcontent">
Karen L.
<br>
Marlene T.
<br>
Joyce A.
<br>
Mickey Z.
</div>

<div id="dropmsg2" class="dropcontent">
Joan T.
<br>
June G.
<br>
Alice G.
<br>
Sandy B.
</div>

<div id="dropmsg3" class="dropcontent">
Mary B.
<br>
Amy S.
<br>
Carol C.
<br>
Dee V.
</div>

<div id="dropmsg4" class="dropcontent">
Bev W.
<br>
Fran D.
<br>
Barb F.
<br>
Gerry B.
</div>

<div id="dropmsg5" class="dropcontent">
Blind
<br>
Lynda F.
<br>
Gail J.
<br>
Val B.
</div>

<div id="dropmsg6" class="dropcontent">
Helen N.
<br>
Sandy S.
<br>
Pat D.
<br>
Blind
</div>

<div id="dropmsg7" class="dropcontent" >
Dora F.
<br>
Yo P.
<br>
Minnie C.
<br>
Blind
</div>

<div id="dropmsg8" class="dropcontent" div align="center">
You Must Bowl NO <br>
LESS THAN ( <INPUT TYPE=text NAME=PPG SIZE=2 MAXLENGTH=3> ) To <br>
Take A Point Per Game!!!
</div>

</form>
</td>

<td>
<form name="dropmsgform1">
<select name="dropmsgoption1" size="1" style="width:275"
onChange="expandone()">
    <option selected>JavaScript?</option>
    <option>Java</option>
    <option>DHTML</option>
</select>
<br>

<div id="dropmsg0" class="dropcontent">
JavaScript is cool.
</div>

<div id="dropmsg1" class="dropcontent">
Html rocks.
</div>

<div id="dropmsg2" class="dropcontent">
DHTML is awesome.
</div>
</form>
</td>

</tr>
</table>
</body>
</html>

2. Display one document in several linked GUI widgets - Java GUI Programming

3. static block run several times (j2ee, apache tomcat)

The way I understand things, a static block should only run once, when the
class is loaded. But in my test case (se below), it is run several times.

The code:

public class Test
{
   private static Test singleton;
   private static int hmm = 0;

   static
   {
      System.out.println("--static block");
      singleton = Test();
   }

   private Test()
   {
      System.out.println("--Creating the Test instance");
      System.out.println("--hmm = " + hmm);
      hmm++;
   }

   public static Test getInstance()
   {
      return singleton;
   }
}

public class TestSessionListener implements HttpSessionListener
{
   private static Test test;

   public TestSessionListener()
   {
      System.out.println("--new TestSessionListener. this = " + this);
      if (test == null)
      {
         test = Test.getInstance();
      }
   }
}

All this is in a web application in Apache Tomcat. Now, if I then restart
Apache Tomcat I get the following output:

--new TestSessionListener. this = TestSessionListener@148bd3
--static block
--Creating the Test instance
--hmm = 0
--new TestSessionListener. this = TestSessionListener@1c92535
--static block
--Creating the Test instance
--hmm = 0
--new TestSessionListener. this = TestSessionListener@b0bad7
--static block
--Creating the Test instance
--hmm = 0
--new TestSessionListener. this = TestSessionListener@1126b07
--static block
--Creating the Test instance
--hmm = 0
--new TestSessionListener. this = TestSessionListener@193722c
--static block
--Creating the Test instance
--hmm = 0
--new TestSessionListener. this = TestSessionListener@3e89c3
--static block
--Creating the Test instance
--hmm = 0

My first question is, how come Apache Tomcat create 6 instances of the class
TestSessionListener? That doesn't make any sense to me. But anyway, what
puzzles me even more is the fact that it seems to create 6 instances of the
Test class, and runs the static block 6 times! How is that possible? Is
there 6 java runtime enviroments running at the same time or something? Is
this a bug?

Regards
/Jimi 


4. Java Script Errors when clicking on several opened documents - Adobe Dreamweaver

5. Cross-browser question: making Netscape recognize frames within document within frame within frame

6. Imbedded </script> within a document.write()

7. Need help with script conflict (Two scripts on one page)

8. Running Perl Script from within javascript