The Web Design Group

... Making the Web accessible to all.

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> JavaScript vertical menu displaying horizontal, Links are also not clickable
BlondOverBlue
post Jul 2 2014, 10:19 AM
Post #1





Group: Members
Posts: 5
Joined: 20-June 14
Member No.: 21,118



I have a very basic web site I am making that is hosted on a shared network drive, so I don't have access to PHP, or SSI. However, the site will be link-intensive with a simple, text-only vertical menu on the left. Instead of updating every single page when I update the links, I'd like to have changes be made automatically across all pages.

I wrote a simple piece of JS, but I can't get it to show vertically; it shows horizontally with no spacing, nor are the links clickable.

It seems given my lack of server-side resources, JavaScript will be my best bet, I think. How do I get this to show "active", display vertically, and with spacing? Below is the code.

CODE


document.write("<div style='color:blue; font-size:12pt;'>");
document.write("Link 1");
document.write("Link 2");
document.write("Link 3");
document.write("Link 4");
document.write("Link 5");
document.write("</div>");

User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Christian J
post Jul 2 2014, 11:02 AM
Post #2


.
********

Group: WDG Moderators
Posts: 9,656
Joined: 10-August 06
Member No.: 7



That script doesn't output any links, just the plain text inside the quotes ("Link 1" etc). Try something like

CODE
document.write('<a href="...">Link 1<\/a> ');

where "..." is the link's URL. (The backslash in the link end tag may not be necessary in today's browsers, it's traditionally used to prevent javascript from thinking the forward slash ended the string.)

There are several ways to make the links display vertically (using either HTML or CSS), which one to use depends on the rest of your page layout.

It's also a good idea to keep CSS in a separate file, instead of using STYLE attributes in the HTML. See http://htmlhelp.com/reference/css/style-html.html
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
BlondOverBlue
post Jul 2 2014, 12:14 PM
Post #3





Group: Members
Posts: 5
Joined: 20-June 14
Member No.: 21,118



QUOTE(Christian J @ Jul 2 2014, 12:02 PM) *

That script doesn't output any links, just the plain text inside the quotes ("Link 1" etc). Try something like

CODE
document.write('<a href="...">Link 1<\/a> ');

where "..." is the link's URL. (The backslash in the link end tag may not be necessary in today's browsers, it's traditionally used to prevent javascript from thinking the forward slash ended the string.)

There are several ways to make the links display vertically (using either HTML or CSS), which one to use depends on the rest of your page layout.

It's also a good idea to keep CSS in a separate file, instead of using STYLE attributes in the HTML. See http://htmlhelp.com/reference/css/style-html.html



Thanks, Christian. I was able to get the links active now. Half the battle...

The vertical positioning is the other half. The site uses a very basic CSS-based layout (header, left menu where these links will be, content area, footer. It's becoming a challenge to try and get this menu created and incorporated into the site.

I think I may just default to using a frames-based layout. Uglier, but it's functional.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Christian J
post Jul 2 2014, 12:46 PM
Post #4


.
********

Group: WDG Moderators
Posts: 9,656
Joined: 10-August 06
Member No.: 7



QUOTE(BlondOverBlue @ Jul 2 2014, 07:14 PM) *

The vertical positioning is the other half. The site uses a very basic CSS-based layout (header, left menu where these links will be, content area, footer.

Make the links "display: block", and they should end up below each other. Then float the DIV, and it should shrink to fit its content:

CODE
<style type="text/css">
#nav  {
float: left;
color: blue;
background: pink;
}

#nav a {display: block;}
</style>

<script type="text/javascript">
document.write('<div id="nav">');
document.write('<a href="">Link 1<\/a> ');
document.write('<a href="">Link 2<\/a> ');
document.write('<a href="">Link 3<\/a> ');
document.write('<\/div>');
</script>


If you want the footer to appear below the nav menu you also need to clear the float:

CODE
footer {clear: left;}


QUOTE
I think I may just default to using a frames-based layout. Uglier, but it's functional.

Frames cause lots of other problems: http://htmlhelp.com/faq/html/frames.html#frame-problems
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post

Reply to this topicStart new topic
2 User(s) are reading this topic (2 Guests and 0 Anonymous Users)
0 Members:

 



- Lo-Fi Version Time is now: 25th April 2024 - 01:42 AM