Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

replacing text in .html page

Status
Not open for further replies.

engcomp

Programmer
Jun 18, 1999
66
AU
I have a page with a table (three columns).
The left column holds the site's main menu.
The right column holds pointers to articles.
The centre column holds several text blocks.
I want to replace one of those text blocks with another according to which pointer the user clicked in the right column.
Can this be done? Or do I have to rebuild the whole page?

 
you need to look at your process. why do you want it to be done in this manner, rather than having separate pages for separate content?

the method you desire can be accomplished with frames or javascript, primarily.

i suggest using neither, but instead re-addressing your underlying functional requirement.



*cLFlaVA
----------------------------
[tt]"quote goes here"[/tt]
[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
Thank you such a prompt response.
Yes, the straight forward solution is to have a separate page for each article, each of which would recreate all of the menus and pointers and non-changing text blocks. This seems wasteful if it is possible to just replace the html code of one central text block?

 
Here is another reason for just replacing part of the html code of a page - if the main menu or article pointer menu or fixed text blocks are changed, every article page has to be updated.

However, there may be a way of loading the "stationary" elements as Javascript variables? Say you have a variable called "pointermenu" that loads into the right-hand column and others called "toptext" and "btmtext" that load respectively above and below the article, and maybe one called "mainmenu" that loads into the left column, then updating the site would not be too onerous.

Can you have a Javascript variable that comprises Javascript code in addition to html?

 
You can load the things that are common to all pages as include files using either Server Side Includes, ASP (both of which use SSI the same way, different extensions), or PHP. I set up websites in modules, the header in one module, buttons in a second, the footer in another, and then use server side scripting to include those on each page. When I want to change something, like add a button, I do it on one page rather than however many pages there are (some sites I've worked on have up to a hundred pages).

I'd recommend the server-side solution over client-side Javascript, though have done that when a client had hosting that wouldn't allow server-side scripting by someone outside the company itself. If the visitor to the site has Javascript turned off, your navigation pretty much disappears with the client-side version.

Lee
 
There are several ways to acomplish this although i don;t think Javascript is the best way.

If you can have access to server-side scripting it would be very easy.

However using an iframe is certainly an option that requires no Javascript, it is just a matter of having your links target the iframe.

Something like:
Code:
<iframe name="mycontent" width=250px height=300px scrolling=yes SRC="noarticlepage.html">
</iframe>

Your links would then need to target the iframe to change the contents such as:

Code:
<a href="article1.html" target="mycontent">
...






----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Let's revert back to cLFlaVA's solution. Separate pages for each article is still the best way to go. Think bookmarking, if nothing else.
 
Thank you all for your contribution.
Seems like "separate pages" is the way to go, because some are likely to be bookmarked.
To make it easy to upgrade, I'd use a Javascript variable for the article list.
Anybody know what percent of users have Javascript turned off?
Thanks again.

 
The reason I prefer Javascript is that I know nothing about SSI. However, reading up on it, I see this comment: "SSI is a great way to add small pieces of information, such as the current time. But if a majority of your page is being generated at the time that it is served, you need to look for some other solution."

In this context, it seems SSI does not make sense for me?

 
But I like the idea of vacunita's iframe suggestion.
This seems to come closest to my original question.
Never used the command before, so I have to read up on it.
Thank you all, for your great comments!

 
vacunita, thank you

I have no problem with "width" - it is the width of my centre column.

I have a problem with "height" and "scrolling" - is it possible to adjust the height to suit the size of the article so that "scrolling" is not necessary?

Finally, instead of "noarticlepage.html", how would you pick an article at random from the available articles when a user first gets to the page?

Thanks again for a fantastic suggestion, Helmut

 
It is so frustrating when you know exactly what you want to achieve, but you don't know the best way to do it, like 'how to eliminate the border around "iframes"'? "border = 0" doesn't work!

 
Anybody know what percent of users have Javascript turned off?
No, but I know that Google doesn't switch it on when crawling your site. If your navigation is hidden in JS, Google won't be able to spider your site. Putting the content in (i)frames may cause problems too.

I see this comment: "SSI is a great way to add small pieces of information, such as the current time. But if a majority of your page is being generated at the time that it is served, you need to look for some other solution."
Whose comment was that? Whoever it was didn't know what (s)he was talking about. SSI is definitely the way to go on this.

-- Chris Hunt
Webmaster & Tragedian
Extra Connections Ltd
 
I agree with Vragabond that SSI's should be the way to acomplish what you want as it is getting to complex to handle via standrd HTML, Having a random article load into the iframe when the page is first opened is better suited with some server side language.

I think you should reconsider, and either look into SSI's or a server-side language (PHP, ASP,...) to help you include your articles.

As we all have said Javascript is highly discouraged.


----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
The quoted comment came from...

But I am concerned about "If your navigation is hidden in JS, Google won't be able to spider your site." My navigation comprises a list of variables, like...
<script type="text/javascript" language="JavaScript">
<!--
home()
screen()
basics()
.
.
etc.
where...
function home() {
document.writeln(" <TABLE class=\"sidemenu\" width=\"85\" border=\"0\" cellspacing=\"0\" cellpadding=\"1\">");
document.writeln(" <TR><TD>");
document.writeln(" <A href=\"index.html\" target=\"_top\">HOME<\/A>");
document.writeln(" <\/TD><\/TR>");
document.writeln(" <TR><TD>");
document.writeln(" <b>Know Your Opponent</b> home page.");
document.writeln(" <HR><\/TD><\/TR>");
}

etc.
You mean that Google won't spider the site because of this?

 
You can do this all server-side, and if you use ASP and want to use JScript as your scripting language (which I do), converting it over will take very little time. I'd still recommend using Server-Side Includes for the sake of simplicity and maintenance, and you could use different includes for the right column on different pages.

Learning to use SSI is simple. Basically all you need to do is find an example, copy and paste it into your HTML in the appropriate spot, and change the file name to whatever is relevant. I currently design sites so besides the includes, the only thing on an HTML page is what's relevant to that particular page.

Lee
 
Lee... go and wash yourself! ASP and JScript?! Together? Ewww!

Seriously though... using JScript and ASP was my first introduction to Javascript all those years ago [smile] Porting from client to server-side is easy.

Cheers,
Jeff

[tt]Jeff's Page @ Code Couch
[/tt]

What is Javascript? FAQ216-6094
 
I prefer the OOP abilities of JScript over VBScript (yes, I know you can have Classes and objects in VBS, too, but not nearly as simply as with JS), and I don't have to switch thinking from one language to another when I move back and forth between client-side and server-side programming. I've been using JScript for ASP since around 2001 when I first started working with ASP, and have done very little VBS ASP since then.

I know it's not the most popular language for ASP, but it works just fine for me. :)#

Maybe ironically, I use VBS for WSH scripts, and VB 6.0 for Win32 executables.

Lee
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top