Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-07-2013, 08:21 PM   PM User | #1
Jmarvig
New Coder

 
Join Date: Feb 2013
Location: Chaska, Minnesota
Posts: 12
Thanks: 3
Thanked 0 Times in 0 Posts
Jmarvig is an unknown quantity at this point
External dropdown menu

For my website, I need a menu that I can change with the uploading of one file to my host, instead of going through and recoding all the menus on many pages.

I have this so far for my menu:

<div id='cssmenu'>
<ul id="nav">

<li><a href="index.html">Home</a>
<li><a href="New Bridges.html ">New Bridges</a>
<li><a href="Cool Bridges.html ">Cool Bridges</a></li>
<li><a href="JMBPcontactpage.html ">Contact Me</a></li>
<li><a href="Mission.html ">About This Site</a></li>
<li><a href="Glossary.html ">Glossary</a></li>
<ul>
<li><a href="IL_COUNTIES ">Illinois Bridges</a>
<ul class="scrollable">
<li><a href="Jo Daviess County.html">Jo Daviess County</a></li>
</ul>
<li><a href="IA_COUNTIES ">Iowa Bridges</a>
<ul class="scrollable">
<li><a href="Dallas County.html">Dallas County</a></li>
<li><a href="Emmet County.html">Emmet County</a></li>
<li><a href="Floyd County.html">Floyd County</a></li>
<li><a href="Hamilton County.html">Hamilton County</a></li>
<li><a href="Polk County IA.html">Polk County</a></li>
<li><a href="Webster County.html">Webster County</a></li>
<li><a href="Wright County IA.html">Wright County</a></li>
</ul>
<li><a href="MN_COUNTIES ">Minnesota Bridges</a>
<ul class="scrollable">
<li><a href="Blue Earth County.html">Blue Earth County</a></li>
<li><a href="Brown County.html">Brown County</a></li>
<li><a href="Carver County.html">Carver County</a></li>
<li><a href="Chippewa County.html">Chippewa County</a></li>
<li><a href="Cottonwood County.html">Cottonwood County</a></li>
<li><a href="Dakota County.html">Dakota County</a></li>
<li><a href="Grant County.html">Grant County</a></li>
<li><a href="Hennepin County.html">Hennepin County</a></li>
<li><a href="Jackson County.html">Jackson County</a></li>
<li><a href="Le Seuer County.html">Le Seuer County</a></li>
<li><a href="Lyon County.html">Lyon County</a></li>
<li><a href="McLeod County.html">McLeod County</a></li>
<li><a href="Morrison County.html">Morrison County</a></li>
<li><a href="Nicollet County.html">Nicollet County</a></li>
<li><a href="Norman County.html">Norman County</a></li>
<li><a href="Otter Tail County.html">Otter Tail County</a></li>
<li><a href="Polk County.html">Polk County</a></li>
<li><a href="Ramsey County.html">Ramsey County</a></li>
<li><a href="Redwood County.html">Redwood County</a></li>
<li><a href="Renville County.html">Renville County</a></li>
<li><a href="Rice County.html">Rice County</a></li>
<li><a href="Scott County.html">Scott County</a></li>
<li><a href="Stearns County.html">Stearns County</a></li>
<li><a href="Steele County.html">Steele County</a></li>
<li><a href="Wadena County.html">Wadena County</a></li>
<li><a href="Waseca County.html">Waseca County</a></li>
<li><a href="Washington County.html">Washington County</a></li>
<li><a href="Yellow Medicine County.html">Yellow Medicine County</a></li>
</ul>
<li><a href="Grand Forks.html ">North Dakota Bridges</a>
<ul class="scrollable">
<li><a href="Grand Forks.html">Grand Forks Area</a></li>
</ul>
<li><a href="WI_COUNTIES ">Wisconsin Bridges</a>
<ul class="scrollable">
<li><a href="Chippewa County WI.html">Chippewa County</a></li>
<li><a href="Dunn County.html">Dunn County</a></li>
<li><a href="Eau Claire County.html">Eau Claire County</a></li>
<li><a href="Polk County WI.html">Polk County</a></li>
</ul>
</div>


How could I get this into an external file, which could be connected to the pages in which I would use it on?

Thanks,
John
Jmarvig is offline   Reply With Quote
Old 02-08-2013, 02:48 AM   PM User | #2
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,248
Thanks: 59
Thanked 3,999 Times in 3,968 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
The easiest way would be to use a server-side languge: PHP or ASP or JSP, all of which allow you to include multiple source files into a single web page.

You could also convert that code into a bunch of JavaScript that would build up DOM objects one at a time.

You could also use JS to read that in as a text file and then dump the contents thereof into the innerHTML of some object on the page.

Both of the JS methods require that the page doing the importing provide some code to specify how and where to put the imported code/data.

The last, not recommended, way would be to use JS code to read in the text and use document.write( ) to put it in place on the code wherever the <script> tags that do the reading are located.

Truly, a server-side solution is the best over all. Use it if you can.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Old 02-08-2013, 03:19 AM   PM User | #3
Jmarvig
New Coder

 
Join Date: Feb 2013
Location: Chaska, Minnesota
Posts: 12
Thanks: 3
Thanked 0 Times in 0 Posts
Jmarvig is an unknown quantity at this point
Quote:
Originally Posted by Old Pedant View Post
The easiest way would be to use a server-side languge: PHP or ASP or JSP, all of which allow you to include multiple source files into a single web page.

You could also convert that code into a bunch of JavaScript that would build up DOM objects one at a time.

You could also use JS to read that in as a text file and then dump the contents thereof into the innerHTML of some object on the page.

Both of the JS methods require that the page doing the importing provide some code to specify how and where to put the imported code/data.

The last, not recommended, way would be to use JS code to read in the text and use document.write( ) to put it in place on the code wherever the <script> tags that do the reading are located.

Truly, a server-side solution is the best over all. Use it if you can.
Then that does raise another question on my side. How would I be able to get that block of coding I already did into a php format?

-John
Jmarvig is offline   Reply With Quote
Old 02-08-2013, 06:35 AM   PM User | #4
boyo1991
New Coder

 
Join Date: Nov 2010
Location: i live online.
Posts: 11
Thanks: 2
Thanked 0 Times in 0 Posts
boyo1991 is an unknown quantity at this point
i personally dont think there are any html to php converters.. but with php, the syntax is actually starting with html:

Code:
<html>
<head>
<title>woop</title>
</head>
<body>
<?php
//php code here
?>
so i highly doubt theres much youd have to worry about.. its about importing it into your index.php, instead of it being index.html...
boyo1991 is offline   Reply With Quote
Old 02-08-2013, 06:37 AM   PM User | #5
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,248
Thanks: 59
Thanked 3,999 Times in 3,968 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
Quote:
Originally Posted by Jmarvig View Post
Then that does raise another question on my side. How would I be able to get that block of coding I already did into a php format?
You don't have to.

You can just name it "whatever.php" *WITH NO CHANGES* and do
Code:
<?php

echo "before the include<hr/>";

include "whatever.php";

echo "after the include<hr/>";
?>
If the included file does not contain <?php ... ?> tags, then it is processed as HTML.

After all, you can always go back and forth between PHP and HTML in *ANY* PHP code:
Code:
<html>
<body>
<h1>This is HTML</h1><br/>
<?php
echo "<h2>This is from PHP code</h2><br/>";
?>
And this is more HTML.<br/>
<?php
echo "And more from PHP code<br/>";
?>
</body>
</html>
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Users who have thanked Old Pedant for this post:
Jmarvig (02-08-2013)
Old 02-08-2013, 06:45 AM   PM User | #6
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,248
Thanks: 59
Thanked 3,999 Times in 3,968 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
Here, look at
http://www.mywhizbang.com/demo2.php

here is the soruce code for demo2.php:
Code:
<html>
<body>
<?php
echo "Before the include<hr/>";

include "getme.php";

echo "After the include<hr/>";
?>
</body>
</html>
And here is the source code for "getme.php":
Code:
<div style="border: solid blue 3px; background-color: lightblue;">
This is just some text in a div
</div>
See? No actual PHP code in the included file.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Users who have thanked Old Pedant for this post:
Jmarvig (02-08-2013)
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:19 PM.


Advertisement
Log in to turn off these ads.