/    Sign up×
Community /Pin to ProfileBookmark

function load order

I have two function being loaded on one onClick. The 2nd function is loaded
before the 1st one is completed. How can I get the 1st function to finish
loading before the 2nd function is loaded. Is there such a command call
sleep or pause that I can set up? I am not that skillful with java scripts.

Thank-u
Cindy
?

to post a comment
JavaScript

16 Comments(s)

Copy linkTweet thisAlerts:
@JonaJul 08.2003 — [font=arial][color=maroon]It would help if you provided a link. Usually, it can be done this way:[/color][/font]

[font=monospace]

onClick="function1(); function2();"

[/font]

[b][J]ona[/b]
Copy linkTweet thisAlerts:
@callwinauthorJul 08.2003 — I have it that way and stiil function 2 (exercise) load before function 1 (segments) is completed.

Here is my line that calls the functions

<INPUT TYPE="button" name="Segments" value="1. Collins" title="Click Here to select this exercise segment;" onClick="

segement(this.form);

exercise(this.form);"

onMouseOver="window.status='Click Here to select this exercise segment';

return true;"


</font style="border: 1px solid #0066FF; background-color: #0066FF"></p>


The segments funtion (function 1) is loading 3 parents iframes .

The exercise (function 2) function is loading a window.open and a parent iframe.

Is there such a command call timeout or pause so that fthe segments function (function 1) can complete loading?

Thanks

Cindy
Copy linkTweet thisAlerts:
@JonaJul 08.2003 — [font=monospace]

onClick="segment(this.form); var loadFunc2 = setTimeout('exercise(this.form)', 1000);"

[/font]

[font=arial][color=maroon]This will run the function one second after it was clicked (should be plenty of time, right?). It's actually one thousand milliseconds. You'll need to add this code to the beginning of exercise() though:[/color][/font]

[font=monospace]

clearTimeout(loadFunc2);

[/font]

[b][J]ona[/b]
Copy linkTweet thisAlerts:
@callwinauthorJul 08.2003 — Hi, does the clearTimeout(loadFunc2) ; go into the exercise function?

Thank-u for helping me.

?
Copy linkTweet thisAlerts:
@JonaJul 08.2003 — [font=arial][color=maroon]Yes, I said it should be the first line in the exercise() function.[/color][/font]

[b][J]ona[/b]
Copy linkTweet thisAlerts:
@callwinauthorJul 09.2003 — I added those lines in and it does not work.

Here is what I have added

Thanks

Cindy

function segement(form) {

parent.I3.location='seg1/actions.html';

parent.pix.location='images/John.jpg';

parent.info.location='seg1/message/John.htm'

}

function getSelectedButton(buttonGroup){

for (var i = 0; i < buttonGroup.length; i++) {

if (buttonGroup[i].checked) {

return i

}

}

return 0

}



function exercise(form) {

clearTime(loadFunc2)

var i = getSelectedButton(form.gender)

if (form.gender[i].value != "John" ) {

alert("You have not choosen any Processor Emulation.")

}

else

if (form.gender[i].value == "John") {

alert("You choosen " + form.gender[i].value + ".")

window.open("images/John.jpg", "sub", "HEIGHT=200,WIDTH=200")

}

endif

endif

}





</SCRIPT>





</head>



<body style="word-spacing: 0; margin: 0; background-color: #0066FF;

vertical-align:top" link="#FFFFFF" vlink="#FFFF00" alink="#00FF00">



<table cellpadding="0" cellspacing="0" style="border-collapse: collapse; word-spacing: 0; margin: 0" width="346" id="AutoNumber2">

<tr>

<FORM METHOD=POST ENCTYPE="text/plain" onReset="return allowReset()" style="text-align: left; word-spacing: 0; margin: 0">

<td width="189" style="word-spacing: 0; border-left-width: 1; border-right: 2px solid #FFFFFF;

border-top-width: 1; border-bottom: 2px solid #FFFFFF; margin: 0">

<p>

<b><font color="#FFFFFF">

<INPUT TYPE="reset" size="10" value="1. Characters" style="color: #FFFFFF;

font-weight: bold;word-spacing: 0; margin: 0; background-color: #0066FF; width:183;

height:0; position:relative; float:left; left:0; top:0";

title="Click here to clear Character;"

onMouseOver="window.status='Click here to clear Characters';"

return true;

onClick="hardReload()"></font></b></td>



<td width="155" style="word-spacing: 0; border-left: 2px solid #FFFFFF;
border-bottom: 2px solid #FFFFFF; margin: 0">
<p style="text-align: center"><b>
<a title="Click here to clear Friends;"
onMouseOver="window.status='Click here to clear Friends';"
return false;
target="_top" href="index.html">2. Friends</a></b></td>

</tr>

<tr>

<td width="189" style="word-spacing: 0; border-right: 2px solid #FFFFFF; margin: 0">

<INPUT TYPE="radio" NAME="gender" value="John"> John<br>

<INPUT TYPE="radio" NAME="gender" value="Josh"> Josh<br>

<INPUT TYPE="radio" NAME="gender" value="KatyBeth"> KatyBeth<br>

<INPUT TYPE="radio" NAME="gender" value="Johnny & Hazel"> Johnny & Hazel<br>

<INPUT TYPE="radio" NAME="gender" value="Sarah"> Sarah<br>

<INPUT TYPE="radio" NAME="gender" value="NoNoBite"> NoNoBite<br>

<INPUT TYPE="radio" NAME="gender" value="Banana"> Banana<br>

<INPUT TYPE="radio" NAME="gender" value="Grassy & Sally"> Grassy & Sally<br>

<br>
<br>

</p>

<td width="48%" style="word-spacing: 0; border-left: 2px solid #FFFFFF; margin: 0" valign="top" align="center">
<p style="margin-top: 0pt; margin-bottom: 0pt;"><font color="#000000">
<INPUT TYPE="button" value="John" name="Segments" title="Click Here to select this Friend;"
onClick="segement(this.form); var loadFunc2 = setTimeout('exercise(ths.form)', 100);"
onMouseOver="window.status='Click Here to select this Friend';
return true;"
style="word-spacing: 0; border: 1px solid #0066FF; margin: 0; background-color: #0066FF"></font> </p>


?
Copy linkTweet thisAlerts:
@Khalid_AliJul 09.2003 — This should do it.

function firstFunc(){

/*

some code here for

*
/

//once the above is done then call the second function

secondFunc();

}

function secondFunc(){

/*

some code here for second function

*
/

}
Copy linkTweet thisAlerts:
@callwinauthorJul 09.2003 — Try that and still does not start the 2nd fucntion (exercise)

Here is part of the code.

function segement(form) {

parent.I3.location='seg1/actions.html';

parent.pix.location='images/John.jpg';

parent.info.location='seg1/message/John.htm'

exercise(this.form)

}

function getSelectedButton(buttonGroup){

for (var i = 0; i < buttonGroup.length; i++) {

if (buttonGroup[i].checked) {

return i

}

}

return 0

}



function exercise(form) {

var i = getSelectedButton(form.gender)

if (form.gender[i].value != "John" ) {

alert("You have not choosen any Processor Emulation.")

}

else

if (form.gender[i].value == "John") {

alert("You choosen " + form.gender[i].value + ".")

window.open("images/John.jpg", "sub", "HEIGHT=200,WIDTH=200")

}

endif

endif

}





</SCRIPT>





</head>



<body style="word-spacing: 0; margin: 0; background-color: #0066FF;

vertical-align:top" link="#FFFFFF" vlink="#FFFF00" alink="#00FF00">



<table cellpadding="0" cellspacing="0" style="border-collapse: collapse; word-spacing: 0; margin: 0" width="346" id="AutoNumber2">

<tr>

<FORM METHOD=POST ENCTYPE="text/plain" onReset="return allowReset()" style="text-align: left; word-spacing: 0; margin: 0">

<td width="189" style="word-spacing: 0; border-left-width: 1; border-right: 2px solid #FFFFFF;

border-top-width: 1; border-bottom: 2px solid #FFFFFF; margin: 0">

<p>

<b><font color="#FFFFFF">

<INPUT TYPE="reset" size="10" value="1. Characters" style="color: #FFFFFF;

font-weight: bold;word-spacing: 0; margin: 0; background-color: #0066FF; width:183;

height:0; position:relative; float:left; left:0; top:0";

title="Click here to clear Character;"

onMouseOver="window.status='Click here to clear Characters';"

return true;

onClick="hardReload()"></font></b></td>



<td width="155" style="word-spacing: 0; border-left: 2px solid #FFFFFF;

border-bottom: 2px solid #FFFFFF; margin: 0">

<p style="text-align: center"><b>

<a title="Click here to clear Friends;"

onMouseOver="window.status='Click here to clear Friends';"

return false;

target="_top" href="index.html">2. Friends</a></b></td>

</tr>

<tr>

<td width="189" style="word-spacing: 0; border-right: 2px solid #FFFFFF; margin: 0">

<INPUT TYPE="radio" NAME="gender" value="John"> John<br>

<INPUT TYPE="radio" NAME="gender" value="Josh"> Josh<br>

<INPUT TYPE="radio" NAME="gender" value="KatyBeth"> KatyBeth<br>

<INPUT TYPE="radio" NAME="gender" value="Johnny & Hazel"> Johnny & Hazel<br>

<INPUT TYPE="radio" NAME="gender" value="Sarah"> Sarah<br>

<INPUT TYPE="radio" NAME="gender" value="NoNoBite"> NoNoBite<br>

<INPUT TYPE="radio" NAME="gender" value="Banana"> Banana<br>

<INPUT TYPE="radio" NAME="gender" value="Grassy & Sally"> Grassy & Sally<br>



<br>

<br>

</p>



<td width="48%" style="word-spacing: 0; border-left: 2px solid #FFFFFF; margin: 0" valign="top" align="center">

<p style="margin-top: 0pt; margin-bottom: 0pt;"><font color="#000000">

<INPUT TYPE="button" value="John" name="Segments" title="Click Here to select this Friend;"

onClick="segement(this.form);"

onMouseOver="window.status='Click Here to select this Friend';

return true;"

style="word-spacing: 0; border: 1px solid #0066FF; margin: 0; background-color: #0066FF"></font> </p>
Copy linkTweet thisAlerts:
@Khalid_AliJul 09.2003 — There is a tonne of errors in your code see the updated code below
<i>
</i>function segement(frm) {
parent.I3.location='seg1/actions.html';//if the parent exists and this code
parent.pix.location='images/John.jpg';//executes then the whole thing will work
parent.info.location='seg1/message/John.htm'
exercise(frm)
}

function getSelectedButton(buttonGroup){
for (var i = 0; i &lt; buttonGroup.length; i++) {
if (buttonGroup[i].checked) {
return i
}
}
return 0
}

function exercise(frm) {
var i = getSelectedButton(frm.gender)
if (frm.gender[i].value != "John" ) {
alert("You have not choosen any Processor Emulation.")
}else if (frm.gender[i].value == "John") {
alert("You choosen " + frm.gender[i].value + ".")
window.open("images/John.jpg", "sub", "HEIGHT=200,WIDTH=200")
}
}
//--&gt;

&lt;/SCRIPT&gt;


&lt;/head&gt;

&lt;body style="word-spacing: 0; margin: 0; background-color: #0066FF;
vertical-align:top" link="#FFFFFF" vlink="#FFFF00" alink="#00FF00"&gt;

&lt;table cellpadding="0" cellspacing="0" style="border-collapse: collapse; word-spacing: 0; margin: 0" width="346" id="AutoNumber2"&gt;
&lt;tr&gt;
&lt;FORM METHOD=POST ENCTYPE="text/plain" onReset="return allowReset()" style="text-align: left; word-spacing: 0; margin: 0"&gt;
&lt;td width="189" style="word-spacing: 0; border-left-width: 1; border-right: 2px solid #FFFFFF;border-top-width: 1; border-bottom: 2px solid #FFFFFF; margin: 0"&gt;
&lt;p&gt;
&lt;b&gt;&lt;font color="#FFFFFF"&gt;
&lt;INPUT TYPE="reset" size="10" value="1. Characters" style="color: #FFFFFF;font-weight: bold;word-spacing: 0; margin: 0; background-color: #0066FF; width:183;height:0; position:relative; float:left; left:0; top:0;" title="Click here to clear Character;"
onMouseOver="window.status='Click here to clear Characters';return true;"
onClick="hardReload()"&gt;&lt;/font&gt;&lt;/b&gt;&lt;/td&gt;

&lt;td width="155" style="word-spacing: 0; border-left: 2px solid #FFFFFF;border-bottom: 2px solid #FFFFFF; margin: 0"&gt;
&lt;p style="text-align: center"&gt;&lt;b&gt;
&lt;a title="Click here to clear Friends;"
onMouseOver="window.status='Click here to clear Friends';return false;"
target="_top" href="index.html"&gt;2. Friends&lt;/a&gt;&lt;/b&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td width="189" style="word-spacing: 0; border-right: 2px solid #FFFFFF; margin: 0"&gt;
&lt;INPUT TYPE="radio" NAME="gender" value="John"&gt; John&lt;br&gt;
&lt;INPUT TYPE="radio" NAME="gender" value="Josh"&gt; Josh&lt;br&gt;
&lt;INPUT TYPE="radio" NAME="gender" value="KatyBeth"&gt; KatyBeth&lt;br&gt;
&lt;INPUT TYPE="radio" NAME="gender" value="Johnny &amp; Hazel"&gt; Johnny &amp; Hazel&lt;br&gt;
&lt;INPUT TYPE="radio" NAME="gender" value="Sarah"&gt; Sarah&lt;br&gt;
&lt;INPUT TYPE="radio" NAME="gender" value="NoNoBite"&gt; NoNoBite&lt;br&gt;
&lt;INPUT TYPE="radio" NAME="gender" value="Banana"&gt; Banana&lt;br&gt;
&lt;INPUT TYPE="radio" NAME="gender" value="Grassy &amp; Sally"&gt; Grassy &amp; Sally&lt;br&gt;

&lt;br&gt;
&lt;br&gt;
&lt;/p&gt;

&lt;td width="48%" style="word-spacing: 0; border-left: 2px solid #FFFFFF; margin: 0" valign="top" align="center"&gt;
&lt;p style="margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;font color="#000000"&gt;
&lt;INPUT TYPE="button" value="John" name="Segments" title="Click Here to select this Friend;"
onClick="segement(this.form);"
onMouseOver="window.status='Click Here to select this Friend';return true;"
style="word-spacing: 0; border: 1px solid #0066FF; margin: 0; background-color: #0066FF"&gt;&lt;/font&gt; &lt;/p&gt;

Copy linkTweet thisAlerts:
@callwinauthorJul 09.2003 — The three parents window load with no problem then the 2nd function whould bave started but does not.

Cindy
Copy linkTweet thisAlerts:
@Khalid_AliJul 09.2003 — The code I posted above is tested so I am just wondering how comeits not working for you(implementation mistakes on your end???)

Upload the rest of code and pages which are directly related to this problem so that I can see what is it you are doing wrong.

(upload as zip file)
Copy linkTweet thisAlerts:
@callwinauthorJul 09.2003 — The main file is called index.html

and the file that has the functions is called charc_friends.html

Thank-u

Cindy

[upl-file uuid=467a7d99-78d2-40b4-80a9-352c4da85661 size=3kB]files.zip[/upl-file]
Copy linkTweet thisAlerts:
@Khalid_AliJul 09.2003 — I am not sure if this is correct or not,but the exercise function is being called,among others the main problem you have is there is no loadFunc2 defined anywhere in the code and you are trying to call clearTime(loadFunc2) on it..

And there is no clearTime function as well..this is the beginning of errors..let me know what you get once you fix them
Copy linkTweet thisAlerts:
@callwinauthorJul 10.2003 — I have added the setTimeout and still get the same problem as before. I have attach the two files.

Thanks

[upl-file uuid=89bcb61d-3fd1-48ff-95ff-2d2fc9b99f19 size=3kB]files1.zip[/upl-file]
Copy linkTweet thisAlerts:
@Khalid_AliJul 10.2003 — You should correct the errors I pointed out above ...
Copy linkTweet thisAlerts:
@callwinauthorJul 10.2003 — I thought I put all the changes back in and added the setTimeout since it was mention that the clearTime... was

in. How do I defined loadFunc2. Would it be better to take out the set Timeout and have the segement function call the exercise function? I have removed all and started over again with the two function being called as the following:

onClick="segment(this.frm); exercise(this.frm);"

Then put the exercise(this.frm) in the exercise fucntion as the last line

Then put onClick="segment(this.frm); var loadFunc2 = setTimeout('exercise(this.frm)' 500);" and added clearTimeou(loadFunc2)' in the exercise fucntion.

So far nothing has been working. What would be the best appoarch.

Would it be best to keep posting or email between each other?

Thanks
×

Success!

Help @callwin spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.26,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...