Forum Moderators: open

Message Too Old, No Replies

modifying script to display more than time

         

mylungsarempty

10:51 am on Aug 30, 2003 (gmt 0)

10+ Year Member



<DIV ID="MyLayer" style="position:absolute;top:10px;
left:10px;">Initial layer text</DIV>

<script language="Javascript">
function WriteLayer(ID,parentID,sText) {
if (document.layers) {
var oLayer;
if(parentID){
oLayer = eval('document.' + parentID + '.document.' + ID + '.document');
}else{
oLayer = document.layers[ID].document;
}
oLayer.open();
oLayer.write(sText);
oLayer.close();
}
else if (parseInt(navigator.appVersion)>=5&&navigator.
appName=="Netscape") {
document.getElementById(ID).innerHTML = sText;
}
else if (document.all) document.all[ID].innerHTML = sText
}
</script>

<form>
<br><br>
<input type="button" value="Display Time" onclick="WriteLayer
('MyLayer',null,Date())">
</form>

That is the script i've started with. It's copied from an article, but the article doesn't go in depth as to how to make a layer display anything other than the date! My JavaScript knowledge is limited, and i imagine it involves coding functions that write the text you want displayed and then calling on them where the Date() function is displayed, but i'm toying with it in Notepad and can't quite get it right... any help with this would be appreciated immensely... thanks```

i dont see an area for strictly javascript related discussion... i see it in the html area though so i thought it would be the best place for it. i was suprised by that.

mylungsarempty

4:55 am on Aug 31, 2003 (gmt 0)

10+ Year Member



nobody knows how to help me out? i dont know why i can't put anything in place of the date... c'mon i know some smart person can get that script to display something other than the date . . .

MonkeeSage

5:58 am on Aug 31, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



What exactly are you trying to get the script to do? Are you trying to display some text instead of the date or what?

"More than one time" -- click the button again...am I missing something?

If you explain what you are trying to do then I'm sure there are several people around who can give you a hand getting it working.

Jordan

mylungsarempty

5:23 am on Sep 1, 2003 (gmt 0)

10+ Year Member



what is this "more than one time" you're quoting... i didn't say that anywhere in my post.

Anyway, i want to change

<form>
<br><br>
<input type="button" value="Display Time" onclick="WriteLayer
('MyLayer',null,Date())">
</form>

to something like

<form>
<br><br>
<input type="button" value="Display Time" onclick="WriteLayer
('MyLayer',null,document.write('words here'))">
</form>

...so Yeah, Text. I just can't see any reason why this wouldn't work. where in the code does sText keep me from doing this? it boggles my mind. If anybody has some insight, i will tell you where a leprechan lives and he will give you some gold.

MonkeeSage

5:41 am on Sep 1, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thread title -> "modifying script to display more than time"

Edit: I misread, sorry. :)

If you just want to write text you can do:

<form>
<br><br>
<input type="button" value="Display Time" onclick="WriteLayer
('MyLayer',null,'Blah blah blah')">
</form>

Jordan

[edited by: MonkeeSage at 5:48 am (utc) on Sep. 1, 2003]

tedster

5:44 am on Sep 1, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The portion between the parentheses after WriteLayer() holds the parameters for that function the code defines -- and that function already writes the third variable to the div, so you don't need another document.write() in there. But you probably should not have a line break - those parameters are part of the WriteLayer() function itself.

Try this:

<form>
<br><br>
<input type="button" value="Display Text" onclick="WriteLayer('MyLayer',null,'text here')">
</form>

<added>
You're faster than I am tonight, Jordan
</added>

mylungsarempty

6:02 am on Sep 1, 2003 (gmt 0)

10+ Year Member



tedster! goodness, i can't believe i was so careless. I tried endless variations of things, because of course the first thing i did was simply replace the Date with some text... but i forgot to enclose the text in single quotes! i KNEW it would be something so simple i could kick myself, but i can't believe i am kicking myself so hard!

Haha, and about that misreading -- i read through my post 4 times trying to find where i said that to see what you meant, and completely forgot what i titled the post. It's my fault for not using the article 'the' . . . i just usually read these titles and they sound like newspaper headlines. I am so happy this works now, thank you, both of you.