Making duplicate code generic

This is a discussion on "Making duplicate code generic" within the Web Page Design section. This forum, and the thread "Making duplicate code generic are both part of the Design Your Website category.



Go Back   Webforumz.com > Main Forums > Design Your Website > Web Page Design

Notices


Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old Jul 14th, 2006, 06:39
Junior Member
Join Date: Jun 2006
Location: England
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Making duplicate code generic

Hi,

I have the following code in 3 diffreent HTML pages:

<select name="select1" size="1" style="background-color:#FFFFD7">
<option value="./a.htm" target="mainFrame">A</option>
<option value="./b.htm" target="mainFrame">B</option>

What im wondering is that is it possible to modularise this in some way like the way javascript can be added to a .js file. Save me duplicating this code 3 times.

I just want a central place for all duplicated code in forms to save me having to change each occurance.

I been told to use Snippets, but doesnt this just make it easier to copy and paste in between pages?

Thanks.
Reply With Quote

  #2 (permalink)  
Old Jul 14th, 2006, 10:02
minute44's Avatar
Moderator
Join Date: Apr 2006
Location: Nottingham UK
Age: 24
Posts: 1,347
Blog Entries: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to minute44
Re: Making duplicate code generic

Quote:
Originally Posted by Rudie View Post
Hi,

I have the following code in 3 diffreent HTML pages:

<select name="select1" size="1" style="background-color:#FFFFD7">
<option value="./a.htm" target="mainFrame">A</option>
<option value="./b.htm" target="mainFrame">B</option>

What im wondering is that is it possible to modularise this in some way like the way javascript can be added to a .js file. Save me duplicating this code 3 times.

I just want a central place for all duplicated code in forms to save me having to change each occurance.

I been told to use Snippets, but doesnt this just make it easier to copy and paste in between pages?

Thanks.
If you're using Dreamweaver or some other WYSIWYG editor then chances are you'll be able to use the library function. this allows you to save imagesm text and code snippets as library items so you can insert them whenever. Kind of like an advanced clipboard.

Hope this helps...
Last Blog Entry: Annoying people.... (Jan 16th, 2008)
Reply With Quote
  #3 (permalink)  
Old Jul 14th, 2006, 10:48
Junior Member
Join Date: Jun 2006
Location: England
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Making duplicate code generic

Yes, Im using Dreamweaver 8. I'll give that a try when i get home.
I know I can re-use javascript code from the .js files but because this is just HTML, didnt want to code the same piece of code 10 times.

Thanks.
Reply With Quote
  #4 (permalink)  
Old Jul 14th, 2006, 10:51
minute44's Avatar
Moderator
Join Date: Apr 2006
Location: Nottingham UK
Age: 24
Posts: 1,347
Blog Entries: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to minute44
Re: Making duplicate code generic

Quote:
Originally Posted by Rudie View Post
Yes, Im using Dreamweaver 8. I'll give that a try when i get home.
I know I can re-use javascript code from the .js files but because this is just HTML, didnt want to code the same piece of code 10 times.

Thanks.
yep, you'll definately be able to do it... you can save anything as a library item in DW. I've done a huge intranet for the place where I work and library items have saved my skin more than once on that project.
Last Blog Entry: Annoying people.... (Jan 16th, 2008)
Reply With Quote
  #5 (permalink)  
Old Jul 14th, 2006, 16:21
Junior Member
Join Date: Jun 2006
Location: England
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Making duplicate code generic

Hi,

Ive highlighted the code I want to make generic but I cant get the button to add the code into the library enabled. Even the option Modify, Library, Add Object To Library is disabled...

How can I enable?

Thanks.
Reply With Quote
  #6 (permalink)  
Old Jul 14th, 2006, 16:32
Rob's Avatar
Rob Rob is offline
Head Admin & CEO

SuperMember
Join Date: Jul 2003
Location: at my desk
Age: 34
Posts: 2,952
Blog Entries: 7
Thanks: 7
Thanked 4 Times in 4 Posts
Send a message via MSN to Rob Send a message via Skype™ to Rob
Re: Making duplicate code generic

Maybe you should consider SSI

This can be done in ASP, PHP, JSP, and any other dynamic scripting language.

It can also be achieved using the .shtml extension should you host support SSI.
__________________
Rob - SEO Specialist
Owner & Founder of Webforumz.com

I am currently unavailable for private work
Reply With Quote
  #7 (permalink)  
Old Jul 14th, 2006, 16:33
Junior Member
Join Date: Jun 2006
Location: England
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Making duplicate code generic

Ok, so cant I use this using normal HTML?
Reply With Quote
  #8 (permalink)  
Old Jul 14th, 2006, 16:36
Junior Member
Join Date: Jun 2006
Location: England
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Making duplicate code generic

Sorted, I had to add a Site.

Thanks.
Reply With Quote
  #9 (permalink)  
Old Jul 14th, 2006, 19:15
Highly Reputable Member
Join Date: Aug 2005
Location: 3rd Branch Up, Old Oak.
Age: 48
Posts: 658
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Making duplicate code generic

I'm just starting to experiment with CSS and I'm just wondering if you could add the code to an external style sheet and just link any pages to it which require this code?
Reply With Quote
  #10 (permalink)  
Old Jul 14th, 2006, 19:20
Junior Member
Join Date: Jun 2006
Location: England
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Making duplicate code generic

Not sure, but I dont like the idea of libraries as its still duplicating code even though a change to the library will update the code used elsewhere.

Surely theres a way to avoid this?

Thanks.
Reply With Quote
  #11 (permalink)  
Old Jul 14th, 2006, 19:22
Most Reputable Member
Join Date: Aug 2005
Location: North Wales, United Kingdom
Age: 21
Posts: 1,093
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to sypher
Re: Making duplicate code generic

Your on the wrong wave length than the comments here Rudie.

Your talking about how to do it in Dreamweaver, whereas the rest of the comments have been about hard coding.
Reply With Quote
  #12 (permalink)  
Old Jul 14th, 2006, 19:27
Junior Member
Join Date: Jun 2006
Location: England
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Making duplicate code generic

Sorry, Eastenders is putting me off ;-)

I basically want to put common code into a seperate place or file and then call it from the web pages where i want to place it, mainly a drop down list.

Hope I make sense.
Reply With Quote
  #13 (permalink)  
Old Jul 14th, 2006, 20:01
Most Reputable Member
Join Date: Apr 2006
Location: Cornwall, UK
Posts: 1,310
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Skype™ to ukgeoff
Re: Making duplicate code generic

I think the point has been missed a few times here.

You put the generic code into a file, e.g., 'generic.inc' which you load on the server alomg with your other html files.

Now, as Rob indicated previously, you use one of the scripting methods to 'include' this file at the appropriate place(s) in your html files.
Reply With Quote
  #14 (permalink)  
Old Jul 14th, 2006, 20:05
Junior Member
Join Date: Jun 2006
Location: England
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Making duplicate code generic

Oh ok, is there an example call somewhere?
Reply With Quote
  #15 (permalink)  
Old Jul 14th, 2006, 21:35
Most Reputable Member
Join Date: Apr 2006
Location: Cornwall, UK
Posts: 1,310
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Skype™ to ukgeoff
Re: Making duplicate code generic

PHP example.

...
...
html code
...

<?php
include ('generic.inc');
?>


...
more html code
...

As Rob stated, if you don;t have access to php but you can use SSI (Server Side Includes), then name your file 'generic.shtml' and use:

<!--#include file='generic.shtml'-->
Reply With Quote
  #16 (permalink)  
Old Jul 14th, 2006, 22:11
Junior Member
Join Date: Jun 2006
Location: England
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Making duplicate code generic

Sorry for sounding thick, but if the generic.shtml (i dont know PHP thats why ive chose SSI) includes my drop down list code, how do I bring in the code from the generic.shtml onto my main page?

Is there a way to wrap it into a function or something?
Reply With Quote
  #17 (permalink)  
Old Jul 14th, 2006, 22:56
Most Reputable Member
Join Date: Apr 2006
Location: Cornwall, UK
Posts: 1,310
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Skype™ to ukgeoff
Re: Making duplicate code generic

You just position the include statement at the point in your html where you want the generic code included.

The server effectively merges the two files together before sending it to the browser.
Reply With Quote
  #18 (permalink)  
Old Jul 15th, 2006, 09:55
Junior Member
Join Date: Jun 2006
Location: England
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Making duplicate code generic

Hi,

Im almost there, ive saved the common code into a .shtml file, called this from within another page, the cut out code shows up in design view, but on execution, it does not show. Can anyone please help?

Thanks.
Reply With Quote
  #19 (permalink)  
Old Jul 15th, 2006, 10:14
Most Reputable Member
Join Date: Apr 2006
Location: Cornwall, UK
Posts: 1,310
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Skype™ to ukgeoff
Re: Making duplicate code generic

Let's see both your generic code and the section of code from your main pages(s) that include the generic code.

Include the code either side of where you include the generic file.
Reply With Quote
  #20 (permalink)  
Old Jul 15th, 2006, 10:20
Junior Member
Join Date: Jun 2006
Location: England
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Making duplicate code generic

./common/dropdown.shtml file:

<div align="right"><img src="./link.gif" alt="Link" width="113" height="27">
<select name="select1" size="1" class="DropBack">
<option value="./sub.htm">Sub</option>
<option value="#"><b>===========</b></option>
<option value="./Red.htm">Red</option>
</select>
<input type="button" value="Go" onClick="jumptolink(document.form1.select1)"
name="button">
</div>


Part of main file:


<TABLE align="center" width="100%">
<tr>
<td></td>
<td width="11%">&nbsp;</td>
<td width="39%"><!--#include file="./Common/dropdown.shtml" --></td>
</tr>
</TABLE>
Reply With Quote
Reply

Tags
making, duplicate, code, generic

Thread Tools

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
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
duplicate content dab42pat Search Engine Optimization (SEO) 25 Aug 3rd, 2007 16:09
Duplicate content ScottR Search Engine Optimization (SEO) 6 Jul 27th, 2007 13:36
live search code and styleswitcher code hebel JavaScript Forum 0 May 12th, 2007 06:16
Generic Window Usage Rudie JavaScript Forum 1 Jun 2nd, 2006 21:21
Can somebody give me the code to hide the source code? renren JavaScript Forum 7 Mar 7th, 2006 12:27


All times are GMT. The time now is 18:12.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43