homepage Welcome to WebmasterWorld Guest from 54.234.128.25
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

    
write a layer with javascript on the body
javascript-only script to write a menu above the body.
sophie




msg:1479122
 1:01 pm on Oct 24, 2001 (gmt 0)

i am noticing some cool dropdown menus use javascript-only script to write a menu on the body. but i don't know how to do it. i know i shouldn't use onload event. but how can i have the new layer in js and body both?

<HTML>
<HEAD>
<SCRIPT LANGUAGE="JavaScript">
<!--
var DivStr,DivID;
var y=300;
var x=300;
var w=110;

function init() {
DivID="Div1";
DivStr="<DIV ID="+ DivID + " style='position:absolute; top:" + y + "; left:" + x + "; width:" + w + "; background-image:url(images/tabs/not_selected.gif);background-repeat: no-repeat;z-index:100;'>"
+"<A HREF='#' target='' onclick='' style='text-decoration: none; color: blue; font-family: arial; font-size:10pt; font-Weight:bold;'>"
+"<p align=center>Above Layer</p>"
+"</a>"
+"</DIV>";
document.write(DivStr);
}

//-->
</SCRIPT>
</HEAD>

<BODY onload=init()>

<table width="700" background="images/styles/blue1x1.gif"><tr><td> </td></tr></table>
</BODY>
</HTML>

 

tedster




msg:1479123
 7:40 pm on Oct 24, 2001 (gmt 0)

Does this do what you want? From the HEAD section, you remove just this line:
document.write(DivStr);

Then in the body, take the onLoad event out of the BODY tag and include the document.write line in a script section:
<script type="text/javascript" language="JavaScript">
<!--

document.write(DivStr);

//-->
</script>

sophie




msg:1479124
 1:45 pm on Oct 26, 2001 (gmt 0)

thank you tedster! it works!

one more question. if DivStr is given a value in a function, just like showed above. it will show "undefined" on the page. do i need some special way to get a variable located in a different script? right now i just comment the function line as follows:

<HTML>
<HEAD>
<SCRIPT LANGUAGE="JavaScript">
<!--
var DivStr,DivID;
var y=300;
var x=300;
var w=110;

//function init() {
DivID="Div1";
DivStr="<DIV ID="+ DivID + " style='position:absolute; top:" + y + "; left:" + x + "; width:" + w + "; background-image:url(images/tabs/not_selected.gif);background-repeat: no-repeat;z-index:100;'>"
+"<A HREF='#' target='' onclick='' style='text-decoration: none; color: blue; font-family: arial; font-size:10pt; font-Weight:bold;'>"
+"<p align=center>Above Layer</p>"
+"</a>"
+"</DIV>";
//}
//-->
</SCRIPT>
</HEAD>

<BODY >
<script type="text/javascript" language="JavaScript">
<!--
document.write(DivStr);
//-->
</script>
<table width="700" background="images/styles/blue1x1.gif"><tr><td> </td></tr></table>
</BODY>
</HTML>

tedster




msg:1479125
 4:52 pm on Oct 26, 2001 (gmt 0)

Sounds right, as long as the variable is defined on this page (or in a js file called from this page). Pulling in a variable associated with a different page is more complex.

If that's your situation, you may find help in this thread:

[webmasterworld.com...]

sophie




msg:1479126
 2:43 pm on Oct 31, 2001 (gmt 0)

thank you for your patience tedster! i learned a lot from that stream.

after my curent assignment about a dynamic selectbox with title content changing in NS, i will work it out and tell you my solution.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved