473,503 Members | 3,721 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

JS: Handling event

12 New Member
There are some js syntax on Event handling which i am not familiar, what could be wrong with the codes below? The words are suppose to change when the mouse move in & out...

<head>
<style>
#bannertext {font-family:"Verdana";}
</style>

<script language="javascript">

// Not sure if the below syntax is correct?

function changeColor(element,color){
element.style.color=color;
}
function changeCursor(element,cursor){
element.style.cursor="hand";
}
function changeContent(element,content){
element.style.content=content;
}
function changeSize(element, size){
element.style.size=size;
}

</script>
</head>
<body>

<!-- I know below codes contain multiple mouse events within a single span & erranous but not sure how to write them -->

<SPAN id="bannertext" onmouseout="changeColor(#bannertext,'blue'); changeContent(bannertext, 'Click me...'); changeSize(bannertext, 20);"

onmouseover="changeText(bannertext,'red'); changeContent(#bannertext, 'Do not Click Me');changeSize(bannertext, 30); changeCursor(this)";

onclick="clickText(bannertext,'green'); changeContent(#bannertext, 'Some text');changeSize(bannertext, 50)";>

Click here to proceed...
</SPAN>
Jan 10 '07 #1
6 1982
iam_clint
1,208 Recognized Expert Top Contributor
fixed you up a bit good luck
Expand|Select|Wrap|Line Numbers
  1. <head>
  2. <style>
  3. #bannertext {font-family:"Verdana";}
  4. </style>
  5. <script language="javascript">
  6. // Not sure if the below syntax is correct?
  7. function changeColor(element,color){
  8. element.style.color=color;
  9. }
  10. function changeCursor(element,cursor){
  11. element.style.cursor="hand";
  12. }
  13. function changeContent(element,content){
  14. element.style.content=content;
  15. }
  16. function changeSize(element, size){
  17. element.style.size=size;
  18. }
  19. </script>
  20. </head>
  21. <body>
  22. <!-- I know below codes contain multiple mouse events within a single span & erranous but not sure how to write them --> 
  23. <SPAN id="bannertext" onmouseout="changeColor(this,'blue'); changeContent(bannertext, 'Click me...'); changeSize(this, 20);"
  24. onmouseover="changeColor(this,'red'); changeContent(this, 'Do not Click Me'); changeSize(this, 30); changeCursor(this)"; 
  25. onclick="changeColor(bannertext,'green'); changeContent(this, 'Some text');changeSize(this, 50)";>
  26. Click here to proceed...
  27. </SPAN>
  28.  
Jan 10 '07 #2
Pete90
12 New Member
Thanks, however the text still remain the same. What is the reason?
Jan 11 '07 #3
acoder
16,027 Recognized Expert Moderator MVP
Thanks, however the text still remain the same. What is the reason?
There's a few mistakes. You can't use content to change content. Use innerHTMl (non-standard) or something similar to change the content. If using innerHTML, use without style directly on the span.

'hand' is not valid, you have to use 'pointer' instead. Your function is not called correctly too.

Instead of size, use fontSize.

That should solve your problems.
Jan 11 '07 #4
Pete90
12 New Member
Actually I have tried both 'pointer' and 'hand', both actually worked! I also tried the playing around with size, fontsize, font-size... doesn't seem to work. There has got to be an easier method than to assign an id & use innerHTML, right?
Jan 12 '07 #5
acoder
16,027 Recognized Expert Moderator MVP
Actually I have tried both 'pointer' and 'hand', both actually worked! I also tried the playing around with size, fontsize, font-size... doesn't seem to work. There has got to be an easier method than to assign an id & use innerHTML, right?
You need to use foneSize (notice the case of S), not fontsize. You don''t need to use an id. Just use
Expand|Select|Wrap|Line Numbers
  1. element.innerHTML = content;
There might be another way too, but this is easy.

If you need more help, let me know.
Jan 12 '07 #6
Pete90
12 New Member
Acoder, thanks... I got it... now it worked. You are correct in saying that it should be fontSize rather than fontsize. Also, simply replacing the function inside with the following resolve the problem:

function changeContent(element,content){
bannertext.innerHTML = content;
}

I find it strange that while other attribute can change its own attribute, but it does not work in the case of the content attribute(i.e. content cannot change content as you mentioned earlier). I am still puzzle as to the reason...
Jan 12 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

7
5966
by: Noor | last post by:
please tell the technique of centralize exception handling without try catch blocks in c#.
2
2084
by: Eric Newton | last post by:
VB's more declarative nature of handling events is golden. I'm hoping C# will acquire this type of deal, in addition to the anonymous delegates. could do same as vb (actually would be easier to...
4
1734
by: hillcountry74 | last post by:
Hi, I'm a newbie and trying to understand event handling in c#. I have understood handling events using delelgate objects. But not this method- "Event handling by overriding the virtual...
3
2062
by: Ashok Kumar K | last post by:
Hi all, Where can I get some insight on using the __hook, __unhook, event_source and event_receiver for specifically COM events. The documentation given in MSDN is very minimal. I have the...
9
2314
by: Sridhar | last post by:
Hi, I have created a web page which includes a place holder. I also have a dropdown list in that webpage. when I select one of the choices in that dropdown list, It will load a user control...
2
2118
by: Paul E. Orman | last post by:
I have a piece of VB code (.NET 1.1 - VB 2003) that loads data from a database through a timer. So the timer is setup and from it I call the procedure that loads the latest records from the...
11
5544
by: chopsnsauce | last post by:
Here's the example: Dim frm As New FORM1 Try frm.show Catch ex As Exception msgbox ex.message
4
2064
by: reggiestyles | last post by:
Hi, I've got a question about prototype and event handling. I've got several div's (dynamic number) on a page that I want to set as active or inactive (basically, I'm using scriptaculous'...
4
1845
by: Mythran | last post by:
I once read an article somewhere describing why we should not override the OnXXX methods of classes when you want to extend the functionality of a class. It stated that you should handle the event...
1
1651
by: stmfc | last post by:
hi, for an event handling mechanism, we need an event object. (the object where the event actually occur) and we need an event handler, and we need a registration of the event handler to the...
0
7192
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,...
0
7064
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...
1
6974
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...
0
5559
agi2029
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,...
1
4991
isladogs
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...
0
3158
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...
0
3147
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
721
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
369
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...

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.