How to change a link's color based on a php variable?
I have a number of links on a page:
<p><a href="page1.php ">Page 1</a></p>
<p><a href="page2.php ">Page 2</a></p>
<p><a href="page3.php ">Page 3</a></p>
<p><a href="page4.php ">Page 4</a></p>
I want the link to be red if $nav has a value that corresponds to the page
number: If $nav = 1, then the page1.php link should be red; if $nav = 2,
then the page2.php link should be red, and so on.
This is how I'd normally code the html to make a red link:
<p><span id="red"><a href="page1.php ">Page 1</a></span></p>
But how do I check the value of $nav and insert the appropriate span id for
each link? Can I somehow make the span id a variable? How to I jump in and
out of php within a tag?
If $nav does not correspond with the link's page number, then the link
should remain the default color - which is blue:
<p><span id="blue"><a href="page1.php ">Page 1</a></span></p>
Any help is appreciated. Thanks in advance. 7 6013
On Wed, 04 Aug 2004 01:58:30 +0000, deko wrote: How to change a link's color based on a php variable?
I have a number of links on a page:
<p><a href="page1.php ">Page 1</a></p> <p><a href="page2.php ">Page 2</a></p> <p><a href="page3.php ">Page 3</a></p> <p><a href="page4.php ">Page 4</a></p>
I want the link to be red if $nav has a value that corresponds to the page number: If $nav = 1, then the page1.php link should be red; if $nav = 2, then the page2.php link should be red, and so on.
This is how I'd normally code the html to make a red link:
<p><span id="red"><a href="page1.php ">Page 1</a></span></p>
But how do I check the value of $nav and insert the appropriate span id for each link? Can I somehow make the span id a variable? How to I jump in and out of php within a tag?
If $nav does not correspond with the link's page number, then the link should remain the default color - which is blue:
<p><span id="blue"><a href="page1.php ">Page 1</a></span></p>
Any help is appreciated. Thanks in advance.
alt.comp.homewo rk -----------> [this way]
I've only been back reading this group again for a week, and so far,
you've asked enough basic questions here for people to have written almost
your entire project. How about using php.net or google rather than being
spoon fed?
I'm all for helping where I can, but there's 'help', and there's 'do it
for me'.
Regards,
Ian
--
Ian.H
digiServ Network
London, UK http://digiserv.net/
I noticed that Message-ID: <ap************ @newssvr27.news .prodigy.com>
from deko contained the following: This is how I'd normally code the html to make a red link:
<p><span id="red"><a href="page1.php ">Page 1</a></span></p>
id should be used where the element is unique. Otherwise use class. And
why have a link to itself? But how do I check the value of $nav and insert the appropriate span id for each link? Can I somehow make the span id a variable? How to I jump in and out of php within a tag?
You need to adopt a more holistic approach to this one. :-) If $nav does not correspond with the link's page number, then the link should remain the default color - which is blue:
<p><span id="blue"><a href="page1.php ">Page 1</a></span></p>
I wouldn't use <span> here. Define your link colours in CSS. a:link,
a:visited etc. Again use a class if you want these links to be
different.
Check this out:
<?php
$links="";
$nav=$_SERVER['PHP_SELF'];
$pages=4;
for($i=1;$i<=$p ages;$i++){
if(strpos($nav, "$i")===fal se){
$links.="<a href=\"page$i.p hp\">Page $i</a><br>";
}
else{
$links.="<span style=\"color: red\">Page $i</span><br>";
}
}
?>
Save and include in all pages. echo $links wherever you need it.
Making it dynamic by counting the number of pages in the directory is
left as an A* exercise...
--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
I noticed that Message-ID:
<pa************ *************** *@bubbleboy.dig iserv.net> from Ian.H
contained the following: I've only been back reading this group again for a week, and so far, you've asked enough basic questions here for people to have written almost your entire project. How about using php.net or google rather than being spoon fed?
I'm all for helping where I can, but there's 'help', and there's 'do it for me'.
Ah, but if we do he'll probably fail because the tutor won't believe
it's his own work >:-)
--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
> You need to adopt a more holistic approach to this one. :-)
Thanks for the reply Geoff. I'd say what I came up with is pretty holistic
:)
I put the entire nav list in a separate php file and then just used <?
include $leftnav; ?> in the page. Now the nav list is centralized and
easier to maintain. I had to send a variable with the url to process the
color changes - which work for named anchors in the same page (I thought I
would need JavaScript to do this).
I read somewhere that I should strip any html from $_SERVER['QUERY_STRING']
before using it... not sure about this...
<?php
function linkcolor($arg) {
$nav = $_SERVER['QUERY_STRING'];
if ( $arg == $nav )
{
return "grnlink";
}
else
{
return "blulink";
}
}
echo
"<p><span id=".linkcolor( "home").">< a href=index.php? home>Home
Page</a></span></p>
<p><span id=".linkcolor( "contact"). "><a
href=contact.ph p?contact>Conta ct</a></span></p>
<p><span id=".linkcolor( "services").">< a
href=services.p hp?services>Pro fessional Services</a></span></p>
<p><span id=".linkcolor( "software").">< a
href=software.p hp?software>Sof tware</a></span></p>
<p><span id=".linkcolor( "projmgt"). "><a href=services.p hp?projmgt>Proj ect
Management</a></span></p>
<p><span id=".linkcolor( "netprog"). "><a href=tech.php?n etprog>.NET
Programming</a></span></p>
<p><span id=".linkcolor( "viscount").">< a
href=stats.php? viscount>Viscou nt</a></span></p>
<p><span id=".linkcolor( "oxp")."><a href=software.p hp?oxp>Organize
XP</a></span></p>
<p><span id=".linkcolor( "tech01")." ><a href=tech.php?t ech01#tech01>Te ch
01</a></span></p>
<p><span id=".linkcolor( "tech02")." ><a href=tech.php?t ech02#tech02>Te ch
02</a></span></p>
<p><span id=".linkcolor( "tech03")." ><a href=tech.php?t ech03#tech03>Te ch
03</a></span></p>"
;
?>
I noticed that Message-ID:
<7X************ *****@newssvr21 .news.prodigy.c om> from deko contained the
following: You need to adopt a more holistic approach to this one. :-)
Thanks for the reply Geoff. I'd say what I came up with is pretty holistic
My way was /much/ neater. :-)
--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
> My way was /much/ neater. :-)
of course... we all like our own code best :) one problem I'm having with
my (unkempt) code is that I can't call it twice in the same page. For
example, let's say the page has a lot of stuff on it and the height is
2000px or more. The left nav list starts at the top of the page and has
about a dozen items:
this link
that link
other link
etc...
But when viewing content further down on the page, the menu list is not
visible. So I tried this in the leftnav div:
[top of page]
<? include $navlist; ?>
....
<p>nbsp;</p>
<p>nbsp;</p>
....
[middle of page]
<? include $navlist; ?>
The idea is to make the same left nav list available further down on the
page. The problem is that the second attempt to include the script results
in the following error:
Fatal error: Cannot redeclare linkcolor() (previously declared in
/home/clearpoi/public_html/cgi-bin/leftnav.php:2) in
/home/clearpoi/public_html/cgi-bin/leftnav.php on line 2
Is there a way to avoid this? Can I call the script without calling the
function?
Here is the script:
<?php
function linkcolor($arg) {
$nav = trim(strip_tags ($_SERVER['QUERY_STRING']));
if ( $arg == $nav )
{
return "grnlink";
}
else
{
return "blulink";
}
}
echo
"<p><span id=".linkcolor( "home").">< a href=index.php? home>Home
Page</a></span></p>
<p><span id=".linkcolor( "contact"). "><a
href=contact.ph p?contact>Conta ct</a></span></p>
<p><span id=".linkcolor( "services").">< a
href=services.p hp?services>Pro fessional Services</a></span></p>
<p><span id=".linkcolor( "software").">< a
href=software.p hp?software>Sof tware</a></span></p>
<p><span id=".linkcolor( "projmgt"). "><a href=services.p hp?projmgt>Proj ect
Management</a></span></p>
<p><span id=".linkcolor( "netprog"). "><a href=tech.php?n etprog>.NET
Programming</a></span></p>
<p><span id=".linkcolor( "oxp")."><a href=software.p hp?oxp>Organize
XP</a></span></p>
<p><span id=".linkcolor( "tech01")." ><a href=tech.php?t ech01#tech01>Te ch
01</a></span></p>
<p><span id=".linkcolor( "tech02")." ><a href=tech.php?t ech02#tech02>Te ch
02</a></span></p>
<p><span id=".linkcolor( "tech03")." ><a href=tech.php?t ech03#tech03>Te ch
03</a></span></p>"
;
?>
I noticed that Message-ID: <5j************ **@newssvr29.ne ws.prodigy.com>
from deko contained the following: Is there a way to avoid this? Can I call the script without calling the function?
Split them up. Include the function once, script many.
However, bear in mind what I said about id. It's supposed to be for
unique elements. Probably won't make much difference though unless you
want to access them with Javascript later on.
--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/ This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Henning Vestergaard Poulsen |
last post by:
Hi, I have a problem that I hope someone can help me with.
I'm building a web page with pictures I've taken with my digital camera. I
have succeded making a javacript that, when clicking on a thumbnail, it
changes the main image.
Now, I would like to put an explanation (and date and some EXIF-info) to
each photo so some text is shown next to the main photo when loaded.
I don't know how to change the text without reloading the whole...
|
by: Csaba2000 |
last post by:
How do I detect when the font size has been changed (especially by user action: either Ctrl+Scroll wheel or View/Text
Size)?
This is just for use on IE 5.5+, but it would be great if there was a generic solution.
Thanks,
Csaba Gabor from New York
|
by: JCO |
last post by:
How would you modify this to include font color to be white:
<style type="text/css">ul,ol{color:white;}</style>
I tried this, but it did not work:
<style type="text/css">font color="#FFFFFF",ul,ol{color:white;}</style>
|
by: Wang, Jay |
last post by:
Hello, all,
I would like to enable some text between <SPAN
url="http://www.testserver.com/">WORD TO BE DRAGGED </SPAN>. I put some
javascript and it will extract http://www.testserver.com/ from the the span
element when I select the whole text in the SPAN and drag it.
However, I want to drag it without have to select the words between the span
element. The default mouse action will only select the words when i move the
mouse. Can...
|
by: developer |
last post by:
Does anyone know what is the way IE treats span tags(<span>) and table
tags(<tr>, <td>)? Should the <span> tag be encolsed in tds and trs if
it placed with other elements that are in a table? Can the span tag
itself contain table tags within it?
I have some scripting code and when I wrap the span in table elements
it does not find the html within the span. Here is an example....
<tr><td colspan="4" align="left"><span...
| |
by: mscir |
last post by:
I'm adding text to a div using innerHTML, and watching the width of the
div using offsetWidth. In IE the offsetWidth increases when the div gets
wider, but in Netscape 7.2 or Firefox 1.0.3 it doesn't. Is there a way I
can find when a div increases its width in non-IE browsers?
TIA,
Mike
|
by: David |
last post by:
Hi,
I'd really appreciate any help. Im trying to change a label over and
over again. I can change it the first time, by using the following
code, however it never works again, how can i do this so it uses the
same element name? This is driving me insane. On the second call to var
spanElm = document.getElementById("FirstNameLengthLabel"); spanElm is
set to NULL.
<script language=javascript>
|
by: Lorenzo Thurman |
last post by:
I would like to have an element, a text string, change into a select
when a mouseover occurs and then change back to text when a selection is
made or when a mouse out occurs. I looked a t using dojo for this,
http://dojotoolkit.org, but this will end up on a production server,
where dojo is not installed and cannot be installed. So, I need another
solution. Can someone give some pointers on how this might be done?
TIA
|
by: silly putty |
last post by:
hello. i have a <tablewith each cell having its own unique ID (see
below). What i want to do is change the CLASS attribute for the SPAN
in one of the cells. i'm currently testing this in IE 6. In my
javascript, i wrote
document.getElementById('0_1').getElementsByTagName("span").setAttribute("className",
"hasEvents");
However, i get the following error message:
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |