TKS
-
Total Posts
:
188
- Scores: 0
-
Reward points
:
0
- Joined: 5/16/2008
-
Status: offline
|
JavaScript - If... Then... Else problem.
Sunday, May 18, 2008 10:56 AM
( permalink)
Hi, the following code is pretty simple and self explanitory, but I haven't quite yet figured out why the delay1() function isn't working... what do you think is the problem? - TKS <html>
<head>
<title>LANF_V0.1</title>
<hta:application
id="objTest"
applicationname="hta test"
scroll="yes"
singleinstance="yes"
>
<script language="vbscript"></script>
<script language="JavaScript">
function showHide(elementid){
if (document.getElementById(elementid).style.display == 'none'){
document.getElementById(elementid).style.display = '';
} else {
document.getElementById(elementid).style.display = 'none';
}
}
function delay1(){
if (document.getElementById('ghj').style.display == 'none'){
showHide('ghj');
timer = setTimeout('showHideReset()', 3000);
} else {
clearTimeout(timer);
showHide('ghj');
}
}
function showHideReset(){
showHide('grts');
showHide('gghy');
}
</script>
</head><body>
<div onclick="delay1()">Click Me!</div>
<span id="ghj" style="display:none;">
<div id="gghy"><img src="http://i287.photobucket.com/albums/ll137/tengokukagesensei/Loading2.gif"></div>
<div id="grts" style="display:none;">CONTENT</div>
</span>
</body>
</html>
|
|
|
|
TNO
-
Total Posts
:
2094
- Scores: 36
-
Reward points
:
0
- Joined: 12/18/2004
- Location: Earth
-
Status: offline
|
RE: JavaScript - If... Then... Else problem.
Sunday, May 18, 2008 1:46 PM
( permalink)
Whats not working exactly? I click the word and a loading image appears, then it changes to content. I click again and the display is toggled back and forth. P.S. Would you like me to clean up your code? I'm a bit of a JS evangelist.
To iterate is human, to recurse divine. -- L. Peter Deutsch
|
|
|
|
TKS
-
Total Posts
:
188
- Scores: 0
-
Reward points
:
0
- Joined: 5/16/2008
-
Status: offline
|
RE: JavaScript - If... Then... Else problem.
Sunday, May 18, 2008 2:15 PM
( permalink)
ORIGINAL: TNO Whats not working exactly? I click the word and a loading image appears, then it changes to content. I click again and the display is toggled back and forth. P.S. Would you like me to clean up your code? I'm a bit of a JS evangelist. Hi TNO, If you toggle the word really fast the loading image that changes to content will eventually start swapping it's order with the showing of the content... " the order changes". So instead of the loading image showing first... the content shows then the loading image. And that looks really stupid! So, I put in a SetTimeOut function to prevent that from happening, but I don't think it's working... perhaps I haven't done the if... then... else properly... But if you can clean that up, that would be greatly appreciated. -TKS
|
|
|
|
TNO
-
Total Posts
:
2094
- Scores: 36
-
Reward points
:
0
- Joined: 12/18/2004
- Location: Earth
-
Status: offline
|
RE: JavaScript - If... Then... Else problem.
Sunday, May 18, 2008 4:45 PM
( permalink)
<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>
<html xmlns='http://www.w3.org/1999/xhtml'>
<head>
<title>LANF_V0.1</title>
<hta:application
id="objTest"
applicationname="hta test"
scroll="yes"
singleinstance="yes" />
<meta http-equiv='Content-Type' content='text/html; charset=UTF-8' />
<script type="text/javascript">
//shorthand
function o(o){return document.getElementById(o)}
document.onclick = function(e){
//crossbrowser event capturing
e = e || window.event;
//what element was clicked on? (crossbrowser)
var tg = (e.target) ? e.target : e.srcElement;
//remember these two elements for future use (faster lookup):
var loading = o("loading");
var content = o("content");
//toggle the display
function toggle(el){
(el.style.display === "none") ? el.style.display = "" : el.style.display = "none";
}
//if the object I clicked on has an id of "target"
if(tg.id === "target"){
//if the loading bar and the content are both hidden:
if(loading.style.display === "none" && content.style.display === "none"){
//then show the loading bar
toggle(loading);
/*
* wait 3 seconds, then hide the loading, and show the content:
* no need to assign this to a variable since we will never cancel it
* also no point in creating another simple function since we can just pass
* it into timeout directly
*/
setTimeout(function(){
toggle(loading);
toggle(content);
},3000);
}
//If the content is displayed (assume the loading image isn't)
else if(content.style.display === ""){
//hide the content
toggle(content);
}
//otherwise don't do anything and let the content "load"
}
}
</script>
</head>
<body>
<!-- Added a pointer so its more intuitive //-->
<div id="target" style="cursor:pointer">
Click Me!
</div>
<!-- Took out the unnecessary wrapper tag //-->
<img id="loading" style="display:none;" src="http://i287.photobucket.com/albums/ll137/tengokukagesensei/Loading2.gif" />
<div id="content" style="display:none;">
CONTENT
</div>
</body>
</html>
<message edited by TNO on Sunday, May 18, 2008 4:48 PM>
To iterate is human, to recurse divine. -- L. Peter Deutsch
|
|
|
|
TKS
-
Total Posts
:
188
- Scores: 0
-
Reward points
:
0
- Joined: 5/16/2008
-
Status: offline
|
RE: JavaScript - If... Then... Else problem.
Sunday, May 18, 2008 5:02 PM
( permalink)
ORIGINAL: TNO <!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>
<html xmlns='http://www.w3.org/1999/xhtml'>
<head>
<title>LANF_V0.1</title>
<hta:application
id="objTest"
applicationname="hta test"
scroll="yes"
singleinstance="yes" />
<meta http-equiv='Content-Type' content='text/html; charset=UTF-8' />
<script type="text/javascript">
//shorthand
function o(o){return document.getElementById(o)}
document.onclick = function(e){
//crossbrowser event capturing
e = e || window.event;
//what element was clicked on? (crossbrowser)
var tg = (e.target) ? e.target : e.srcElement;
//remember these two elements for future use (faster lookup):
var loading = o("loading");
var content = o("content");
//toggle the display
function toggle(el){
(el.style.display === "none") ? el.style.display = "" : el.style.display = "none";
}
//if the object I clicked on has an id of "target"
if(tg.id === "target"){
//if the loading bar and the content are both hidden:
if(loading.style.display === "none" && content.style.display === "none"){
//then show the loading bar
toggle(loading);
/*
* wait 3 seconds, then hide the loading, and show the content:
* no need to assign this to a variable since we will never cancel it
* also no point in creating another simple function since we can just pass
* it into timeout directly
*/
setTimeout(function(){
toggle(loading);
toggle(content);
},3000);
}
//If the content is displayed (assume the loading image isn't)
else if(content.style.display === ""){
//hide the content
toggle(content);
}
//otherwise don't do anything and let the content "load"
}
}
</script>
</head>
<body>
<!-- Added a pointer so its more intuitive //-->
<div id="target" style="cursor:pointer">
Click Me!
</div>
<!-- Took out the unnecessary wrapper tag //-->
<img id="loading" style="display:none;" src="http://i287.photobucket.com/albums/ll137/tengokukagesensei/Loading2.gif" />
<div id="content" style="display:none;">
CONTENT
</div>
</body>
</html> Hi TNO, Holy s**t, you cleaned my code up good! Thanks. -TKS
|
|
|
|
TKS
-
Total Posts
:
188
- Scores: 0
-
Reward points
:
0
- Joined: 5/16/2008
-
Status: offline
|
RE: JavaScript - If... Then... Else problem.
Sunday, May 18, 2008 11:59 PM
( permalink)
ORIGINAL: TNO <!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>
<html xmlns='http://www.w3.org/1999/xhtml'>
<head>
<title>LANF_V0.1</title>
<hta:application
id="objTest"
applicationname="hta test"
scroll="yes"
singleinstance="yes" />
<meta http-equiv='Content-Type' content='text/html; charset=UTF-8' />
<script type="text/javascript">
//shorthand
function o(o){return document.getElementById(o)}
document.onclick = function(e){
//crossbrowser event capturing
e = e || window.event;
//what element was clicked on? (crossbrowser)
var tg = (e.target) ? e.target : e.srcElement;
//remember these two elements for future use (faster lookup):
var loading = o("loading");
var content = o("content");
//toggle the display
function toggle(el){
(el.style.display === "none") ? el.style.display = "" : el.style.display = "none";
}
//if the object I clicked on has an id of "target"
if(tg.id === "target"){
//if the loading bar and the content are both hidden:
if(loading.style.display === "none" && content.style.display === "none"){
//then show the loading bar
toggle(loading);
/*
* wait 3 seconds, then hide the loading, and show the content:
* no need to assign this to a variable since we will never cancel it
* also no point in creating another simple function since we can just pass
* it into timeout directly
*/
setTimeout(function(){
toggle(loading);
toggle(content);
},3000);
}
//If the content is displayed (assume the loading image isn't)
else if(content.style.display === ""){
//hide the content
toggle(content);
}
//otherwise don't do anything and let the content "load"
}
}
</script>
</head>
<body>
<!-- Added a pointer so its more intuitive //-->
<div id="target" style="cursor:pointer">
Click Me!
</div>
<!-- Took out the unnecessary wrapper tag //-->
<img id="loading" style="display:none;" src="http://i287.photobucket.com/albums/ll137/tengokukagesensei/Loading2.gif" />
<div id="content" style="display:none;">
CONTENT
</div>
</body>
</html> Hi TNO, Ok, I've probed your code some bit, and I notice that when I replace the text (with id=target) it doesn't work. Here's an example of what I've been doing:
<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>
<html>
<html>
<head>
<title>LANF_V0.1</title>
<hta:application
id="objTest"
applicationname="hta test"
scroll="yes"
singleinstance="yes" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" href="Style.css" type="text/css">
<script language="vbscript" src="scripts/list_avatars.vbs"></script>
<script language="vbscript" src="scripts/savetofile.vbs"></script>
<script language="vbscript" src="scripts/iferror.vbs"></script>
<script language="vbscript" src="scripts/PTandEA.vbs"></script>
<script language="vbscript" src="scripts/erasepost.vbs"></script>
<script language="vbscript" src="scripts/CCCondition.vbs"></script>
<script language="vbscript" src="scripts/ClearContents.vbs"></script>
<script language="vbscript" src="scripts/ClearContents.vbs"></script>
<script language="vbscript">
sub nametextareablur
obj1 = username.value
if obj1="" then
msgbox ("dick!... fill the ****ing feild!")
else
msgbox ("u made an entry nigger!")
end if
end sub
</script>
<script language="JavaScript">
function insertAtCursor( myValue) {
myField = document.getElementById("testID");
//IE support
if (document.selection) {
myField.focus();
sel = document.selection.createRange();
sel.text = myValue;
}
//MOZILLA/NETSCAPE support
else if (myField.selectionStart || myField.selectionStart == '0') {
var startPos = myField.selectionStart;
var endPos = myField.selectionEnd;
myField.value = myField.value.substring(0, startPos)
+ myValue
+ myField.value.substring(endPos, myField.value.length);
} else {
myField.value += myValue;
}
}
</script>
<script type="text/javascript">
//shorthand
function o(o){return document.getElementById(o)}
document.onclick = function(e){
//crossbrowser event capturing
e = e || window.event;
//what element was clicked on? (crossbrowser)
var tg = (e.target) ? e.target : e.srcElement;
var ug = (e.target2) ? e.target2 : e.srcElement;
//remember these two elements for future use (faster lookup):
var loading = o("loading");
var content = o("content");
var rbullet = o("rbullet");
var dbullet = o("dbullet");
var loading2 = o("loading2");
var content2 = o("content2");
var rbullet2 = o("rbullet2");
var dbullet2 = o("dbullet2");
//toggle the display
function toggle(el){
(el.style.display === "none") ? el.style.display = "" : el.style.display = "none";
}
//if the object I clicked on has an id of "target"
if(tg.id === "target"){
//if the loading bar and the content are both hidden:
if(loading.style.display === "none" && content.style.display === "none"){
//then show the loading bar
toggle(loading);
toggle(rbullet);
toggle(dbullet);
/*
* wait 3 seconds, then hide the loading, and show the content:
* no need to assign this to a variable since we will never cancel it
* also no point in creating another simple function since we can just pass
* it into timeout directly
*/
setTimeout(function(){
toggle(loading);
toggle(content);
},1000);
}
//If the content is displayed (assume the loading image isn't)
else if(content.style.display === ""){
//hide the content
toggle(content);
toggle(rbullet);
toggle(dbullet);
}
//otherwise don't do anything and let the content "load"
}
if(ug.id === "target2"){
if(loading2.style.display === "none" && content2.style.display === "none"){
toggle(loading2);
toggle(rbullet2);
toggle(dbullet2);
setTimeout(function(){
toggle(loading2);
toggle(content2);
},1000);
}
else if(content2.style.display === ""){
toggle(content2);
toggle(rbullet2);
toggle(dbullet2);
}
}
}
</script>
</head>
<body>
<div id="target" style="width:500px;
border-width:0px;
padding-bottom:10px;
cursor:pointer;">
<table border="0" cellpadding="0" cellspacing="0" width="500px">
<tr>
<td style="height:1px;
width:500px;
background-color:rgb(177,189,214);">
</td>
</tr>
<tr>
<td style="background-color:rgb(247,247,247);">
<span style="bottom-padding:5px;
font-weight:bold;
font-size:8pt;
color:rgb(59,89,152);
padding-left:8px;
font-family:Verdana,sans-serif;">
<img id="rbullet" src="RightPointingTriangle.bmp" />
<img id="dbullet" src='DownPointingTriangle.bmp' style="display:none;">
Reset ChatBox
<span style="color:rgb(247,247,247);">
--------------------------------------------------------------
</span>
</span>
</td>
</tr>
</table>
</div>
<img id="loading" style="display:none;" src="http://i287.photobucket.com/albums/ll137/tengokukagesensei/Loading2.gif" />
<div id="content" style="display:none;">
CONTENT
</div>
<div id="target2" style="cursor:pointer">
<img id="rbullet2" src="RightPointingTriangle.bmp" /><img id="dbullet2" src="DownPointingTriangle.bmp" style="display:none" />Click Me!
</div>
<img id="loading2" style="display:none;" src="http://i287.photobucket.com/albums/ll137/tengokukagesensei/Loading2.gif" />
<div id="content2" style="display:none;">
CONTENT
</div>
</body>
</html>
-TKS
<message edited by TKS on Monday, May 19, 2008 12:01 AM>
|
|
|
|
TKS
-
Total Posts
:
188
- Scores: 0
-
Reward points
:
0
- Joined: 5/16/2008
-
Status: offline
|
RE: JavaScript - If... Then... Else problem.
Monday, May 19, 2008 6:50 AM
( permalink)
ORIGINAL: TKS ORIGINAL: TNO <!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>
<html xmlns='http://www.w3.org/1999/xhtml'>
<head>
<title>LANF_V0.1</title>
<hta:application
id="objTest"
applicationname="hta test"
scroll="yes"
singleinstance="yes" />
<meta http-equiv='Content-Type' content='text/html; charset=UTF-8' />
<script type="text/javascript">
//shorthand
function o(o){return document.getElementById(o)}
document.onclick = function(e){
//crossbrowser event capturing
e = e || window.event;
//what element was clicked on? (crossbrowser)
var tg = (e.target) ? e.target : e.srcElement;
//remember these two elements for future use (faster lookup):
var loading = o("loading");
var content = o("content");
//toggle the display
function toggle(el){
(el.style.display === "none") ? el.style.display = "" : el.style.display = "none";
}
//if the object I clicked on has an id of "target"
if(tg.id === "target"){
//if the loading bar and the content are both hidden:
if(loading.style.display === "none" && content.style.display === "none"){
//then show the loading bar
toggle(loading);
/*
* wait 3 seconds, then hide the loading, and show the content:
* no need to assign this to a variable since we will never cancel it
* also no point in creating another simple function since we can just pass
* it into timeout directly
*/
setTimeout(function(){
toggle(loading);
toggle(content);
},3000);
}
//If the content is displayed (assume the loading image isn't)
else if(content.style.display === ""){
//hide the content
toggle(content);
}
//otherwise don't do anything and let the content "load"
}
}
</script>
</head>
<body>
<!-- Added a pointer so its more intuitive //-->
<div id="target" style="cursor:pointer">
Click Me!
</div>
<!-- Took out the unnecessary wrapper tag //-->
<img id="loading" style="display:none;" src="http://i287.photobucket.com/albums/ll137/tengokukagesensei/Loading2.gif" />
<div id="content" style="display:none;">
CONTENT
</div>
</body>
</html> Hi TNO, Ok, I've probed your code some bit, and I notice that when I replace the text (with id=target) it doesn't work. Here's an example of what I've been doing:
<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>
<html>
<html>
<head>
<title>LANF_V0.1</title>
<hta:application
id="objTest"
applicationname="hta test"
scroll="yes"
singleinstance="yes" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" href="Style.css" type="text/css">
<script language="vbscript" src="scripts/list_avatars.vbs"></script>
<script language="vbscript" src="scripts/savetofile.vbs"></script>
<script language="vbscript" src="scripts/iferror.vbs"></script>
<script language="vbscript" src="scripts/PTandEA.vbs"></script>
<script language="vbscript" src="scripts/erasepost.vbs"></script>
<script language="vbscript" src="scripts/CCCondition.vbs"></script>
<script language="vbscript" src="scripts/ClearContents.vbs"></script>
<script language="vbscript" src="scripts/ClearContents.vbs"></script>
<script language="vbscript">
sub nametextareablur
obj1 = username.value
if obj1="" then
msgbox ("dick!... fill the ****ing feild!")
else
msgbox ("u made an entry nigger!")
end if
end sub
</script>
<script language="JavaScript">
function insertAtCursor( myValue) {
myField = document.getElementById("testID");
//IE support
if (document.selection) {
myField.focus();
sel = document.selection.createRange();
sel.text = myValue;
}
//MOZILLA/NETSCAPE support
else if (myField.selectionStart || myField.selectionStart == '0') {
var startPos = myField.selectionStart;
var endPos = myField.selectionEnd;
myField.value = myField.value.substring(0, startPos)
+ myValue
+ myField.value.substring(endPos, myField.value.length);
} else {
myField.value += myValue;
}
}
</script>
<script type="text/javascript">
//shorthand
function o(o){return document.getElementById(o)}
document.onclick = function(e){
//crossbrowser event capturing
e = e || window.event;
//what element was clicked on? (crossbrowser)
var tg = (e.target) ? e.target : e.srcElement;
var ug = (e.target2) ? e.target2 : e.srcElement;
//remember these two elements for future use (faster lookup):
var loading = o("loading");
var content = o("content");
var rbullet = o("rbullet");
var dbullet = o("dbullet");
var loading2 = o("loading2");
var content2 = o("content2");
var rbullet2 = o("rbullet2");
var dbullet2 = o("dbullet2");
//toggle the display
function toggle(el){
(el.style.display === "none") ? el.style.display = "" : el.style.display = "none";
}
//if the object I clicked on has an id of "target"
if(tg.id === "target"){
//if the loading bar and the content are both hidden:
if(loading.style.display === "none" && content.style.display === "none"){
//then show the loading bar
toggle(loading);
toggle(rbullet);
toggle(dbullet);
/*
* wait 3 seconds, then hide the loading, and show the content:
* no need to assign this to a variable since we will never cancel it
* also no point in creating another simple function since we can just pass
* it into timeout directly
*/
setTimeout(function(){
toggle(loading);
toggle(content);
},1000);
}
//If the content is displayed (assume the loading image isn't)
else if(content.style.display === ""){
//hide the content
toggle(content);
toggle(rbullet);
toggle(dbullet);
}
//otherwise don't do anything and let the content "load"
}
if(ug.id === "target2"){
if(loading2.style.display === "none" && content2.style.display === "none"){
toggle(loading2);
toggle(rbullet2);
toggle(dbullet2);
setTimeout(function(){
toggle(loading2);
toggle(content2);
},1000);
}
else if(content2.style.display === ""){
toggle(content2);
toggle(rbullet2);
toggle(dbullet2);
}
}
}
</script>
</head>
<body>
<div id="target" style="width:500px;
border-width:0px;
padding-bottom:10px;
cursor:pointer;">
<table border="0" cellpadding="0" cellspacing="0" width="500px">
<tr>
<td style="height:1px;
width:500px;
background-color:rgb(177,189,214);">
</td>
</tr>
<tr>
<td style="background-color:rgb(247,247,247);">
<span style="bottom-padding:5px;
font-weight:bold;
font-size:8pt;
color:rgb(59,89,152);
padding-left:8px;
font-family:Verdana,sans-serif;">
<img id="rbullet" src="RightPointingTriangle.bmp" />
<img id="dbullet" src='DownPointingTriangle.bmp' style="display:none;">
Reset ChatBox
<span style="color:rgb(247,247,247);">
--------------------------------------------------------------
</span>
</span>
</td>
</tr>
</table>
</div>
<img id="loading" style="display:none;" src="http://i287.photobucket.com/albums/ll137/tengokukagesensei/Loading2.gif" />
<div id="content" style="display:none;">
CONTENT
</div>
<div id="target2" style="cursor:pointer">
<img id="rbullet2" src="RightPointingTriangle.bmp" /><img id="dbullet2" src="DownPointingTriangle.bmp" style="display:none" />Click Me!
</div>
<img id="loading2" style="display:none;" src="http://i287.photobucket.com/albums/ll137/tengokukagesensei/Loading2.gif" />
<div id="content2" style="display:none;">
CONTENT
</div>
</body>
</html>
-TKS Hey TNO, Nevermind. I figured out why it wasn't working. -TKS
|
|
|
|