473,811 Members | 2,631 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to change style of a clicked-on hyperlink

hi,
i have a list of hyperlinks (server-side generated), that have a href
value as follows:
href="javascrip t:AsyncRequest( 'someurl.asmx?. .',this)"

since the url is loaded asynchronously, i need to change the style of
the link after it gets clicked to let them know which one they clicked
on, e.g. set a background color or something. i have had difficulty
getting access to the style of the sending element.

i tried the following code to no avail.
function AsyncRequest(ur l, sender)
{
sender.style = "background-color:#000;"; // doesn't work
event.srcElemen t.style = "background-color:#000;"; // doesn't work
....
}

the event.srcElemen t approach gives me 'object required' errors in IE6
and firefox. i should mention that it would be difficult to generate a
unique ID for each hyperlink.

thanks for any tips
tim

Jul 23 '05 #1
4 4574
Ivo
"Tim_Mac" wrote
sender.style = "background-color:#000;"; // doesn't work


Try this:
sender.style.ba ckgroundColor = "#000";

The style object provides access to the usual style properties, but then
written in camelCase as shown. And color values don't need a semicolon
within the quotes.
hth
Ivo
Jul 23 '05 #2
hi Ivo,
thanks for the reply. when i try that, firefox tells me "style has no
properties" and IE6 tells me "style is null or not an object".

i'm using a referenced source file:
<script language="javas cript" src="../AsyncWeb.js"></script>

and here is a sample A tag from my code:
<a
href='javascrip t:Record("../Select.asmx/EnterPreference ?ID=29488&pref= Direct-Conflict",this) '
Direct Conflict</a>


i tried some debugging and when i did an alert(typeof sender), i get
'object window', i would have thought this should be hyperlink or
something?

thanks for any tips
tim

Jul 23 '05 #3
Ivo
"Tim_Mac" <ti*@mackey.i e> wrote
<a

href='javascrip t:Record("../Select.asmx/EnterPreference ?ID=29488&pref= Direct
-Conflict",this) '
Direct Conflict</a>


i tried some debugging and when i did an alert(typeof sender), i get
'object window', i would have thought this should be hyperlink or
something?


Hm, try putting the function call in a proper onclick event handler rather
than using the javascript: pseudo-protocol. Like so:

<a href=""
onclick="return Record('../Select.asmx?etc .',this);">Dire ct Conflict</a>

and return false from the function to prevent the href being followed. Even
better, specify an url to a page for those without javascript in that href,
that is the official way. See the FAQ of this newsgroup:
<URL: http://jibbering.com/faq/#FAQ4_24 >

hth
Ivo


Jul 23 '05 #4
Genius!!
ivo that has made my day. thanks a million for your help. it works
perfectly.

for anyone else who is using asynchronous requests, i noticed a useful
trick to allow non-javascript clients to still use the links, without
having to duplicate the actual href in the onclick handler: just use
'this.href' in the javascript function. probably obvious to folks like
Ivo but i thought i'd post it here for future reference.

<a href='Select.as mx?ID=1234&' onclick='return
SendAsync(this. href,this)'>Wha tever</a>

*********** javascript source ***********
var xmlhttp;

function SendAsync(url, sender)
{
// change the colour of the link to give some feedback to the user
sender.style.ba ckgroundColor = "#000";
sender.style.co lor = "#FFF";

if (window.XMLHttp Request)
{
xmlhttp=new XMLHttpRequest( )
xmlhttp.onready statechange=xml httpChange
xmlhttp.open("G ET",url,true)
xmlhttp.send(nu ll)
}
// code for IE
else if (window.ActiveX Object)
{
xmlhttp=new ActiveXObject(" Microsoft.XMLHT TP")
if (xmlhttp)
{
xmlhttp.onready statechange=xml httpChange
xmlhttp.open("G ET",url,true)
xmlhttp.send()
}
}
return false;
}

function xmlhttpChange()
{
// if xmlhttp shows "loaded"
if (xmlhttp.readyS tate==4)
{
// if "OK"
if (xmlhttp.status ==200)
{
alert(xmlhttp.r esponseText);
}
else
{
alert("Problem retrieving XML data")
}
}
}

Jul 23 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
18580
by: liglin | last post by:
The following script changes the color of text with the onmousover event. How can it be modified so it changes the text when the button is clicked? I'd want to avoid layers or CSS. Thanks, Liglin <HTML> <HEAD> <TITLE>Untitled Document</TITLE>
4
3127
by: Andrea | last post by:
Hi everyone. I'm working on a navigation menu (in a frameset) that I want to set the "active" link to black (the link that corresponds to the page displayed in the right side of the frame) to black. http://www.personal.psu.edu/axg251/wc In the original external style sheet, I set the a:link, a:visited, a:active, and a:hover. That works fine. In the navigation page, I call a function for onclick - it sets the
2
4119
by: deko | last post by:
I'm trying to change the font style of a link when that link is clicked. But the link (sometimes) includes a named anchor. So I need to test for a given named anchor and apply style changes if the test is true - since there will be several different named anchors in the page. I don't think this is very advanced, but I'm new to JavaScript . I code the link like this: <p><span id="currentlink"><a href="techpage.php#tech02"...
6
1950
by: SPG | last post by:
Hi, I wrote a little bit of script that loads an image from a thumbnail when the thumbnail is clicked. It is not very clever, and I have found it only works in IE.. could someone have a look at the script below and suggest how I can make it work in netscape too? Steve
1
2286
by: Yeah | last post by:
I have a multiple choice quiz where I would like to use CSS to change the color of the answers upon clicking them. I would like to present the right and wrong answers up front, rather than direct the user to a separate page with all correct answers. Do the answers have to be "links" for this to work? They have to be inactive links, because they don't actually go anywhere. They only serve the purpose of changing color whether they're...
1
2768
by: kwicher | last post by:
Hi! I hope I will be able to escribe my problem clear enough. So I have the following definition in CSS file. #links { ...... } #links a { ........ }
3
10647
by: Robert | last post by:
Hi, Is it possible to dynamically change the style of a class instead of just an individual element? If so could you point me in the right direction? Robert
2
4835
by: lghtslpr | last post by:
I have an imagemap with several hotspots, and I want a Google Maps-style "floating bubble" to appear when a hotspot is clicked. The bubble would contain some text, a picture, and a close button. I understand that this is generally done with a div positioned at the right place and you make it appear and disappear by controlling its "display" property. But some of the details are unclear to me. How is the close button handled? What about the...
2
1508
by: pamelafluente | last post by:
Hi I am back with a question. I have something like: <span id ="SomeID1" onclick = "Clicked(this.id)"<div class=c1> Something here </div></span> <span id ="SomeID2" onclick = "Clicked(this.id)"<div class=c2> Something here </div></span> <span id ="SomeID3" onclick = "Clicked(this.id)"<div class=c3> Something here </div></span>
1
2613
by: SSG | last post by:
Dear All, I have 10 text boxes... first 5 text boxes e visible , rest of the 5 are hidden... once i clicked the button , the hidden boxes should be visble.. can anyone help me hpw to write script? Regards,
0
9730
marktang
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...
0
9605
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10651
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10392
jinu1996
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...
1
10403
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,...
0
5693
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4341
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3868
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3020
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.