| View previous topic :: View next topic |
| Author |
Message |
MaartenV New member

Joined: 13 Aug 2002 Posts: 3
|
Posted: Tue Aug 13, 2002 6:54 am Post subject: javascript: onmouseover"style.font="'bold'" |
|
|
Hello,
i have the following line in my HTML page:
<a href="blablabl" onmouseover="style.font='bold'" onmouseout="style.font='normal">
now this actually works the way i want, but i do get an "error on page" error in iexplorer, it says "invalid argument". What can this be? Is the bold or normal argument not right or do i have to use something else to than style.font to change the font ?
thx Maarten |
|
| Back to top |
|
 |
phil karras Senior Member

Joined: 15 Jul 2002 Posts: 1776 Location: MD
|
Posted: Tue Aug 13, 2002 7:05 am Post subject: |
|
|
Try debugging it.
1. Move the line up or down to see if the line number of the error line changes (keep all other lines in the same numeric line positions, you may need to add blank buffer lines before & after this line in order to do this.)
2. move other lines below/above this line & leave this line at the same location to see if the error line number changes. (You may need to add comment lines above so you can move the above lines down & delete a comment line to keep this line at the same location.) If this line stays in the same location and the error line number changes the error is either before or after this line, as indicated by which group you moved.
If the error line number does not change then this line is the problem, try:
3. remove each statement one at a time to see if the line still gives the error.
Still gives error?
4. remove both the possible offending statements from the line.
If you still have an error then it's due to something else that's still there.
This is the way I debug something. I first make sure I'm really dealing with the line JS says is the problem. Then I debug the line that when I move it the error line number changes even if the line number is wrong. This has never failed in getting to the root of the problem. _________________ Phil K
Circle Software Consulting
Test website: http://cs.yrex.com/
Guidelines for Posting: http://www.jsworkshop.com/posting.html
IHBAAA = It Has Been Asked And Answered
KISS: http://www.jsworkshop.com/bb/viewtopic.php?t=508 |
|
| Back to top |
|
 |
MaartenV New member

Joined: 13 Aug 2002 Posts: 3
|
Posted: Tue Aug 13, 2002 7:14 am Post subject: |
|
|
| Yes i already tried that, but its really one of the two statements, i just dont see what is wrong with them... |
|
| Back to top |
|
 |
phil karras Senior Member

Joined: 15 Jul 2002 Posts: 1776 Location: MD
|
Posted: Tue Aug 13, 2002 7:17 am Post subject: |
|
|
it might be something like this is needed?:
onmouseover="javascript:style.font='bold'"
or
onmouseover="document.style.font='bold'"
or a combination of the two:
onmouseover="javascript:document.style.font='bold'"
As far as I know you need to specify the scope or where the style is changing. The problem above is that "document" is NOT an ID so it may not be right either, but I think that's what you're looking for.
When you find the answer please post it.
OK, I got it! This problem was not before but after, there is no style called "font" for bold etc it is fontWeight, for JS and font-weight for css.
Also, all the above work when you use fontWeight.
| Code: |
<a href="blablabl" id='Bla01' onmouseover="javascript:Bla01.style.fontWeight='bold'" onmouseout="javascript:Bla01style.fontWeight='normal">
|
Perhaps Michael can tell us if we really need the javascript:Bla01. part(s) to be compatible with other browsers or not. _________________ Phil K
Circle Software Consulting
Test website: http://cs.yrex.com/
Guidelines for Posting: http://www.jsworkshop.com/posting.html
IHBAAA = It Has Been Asked And Answered
KISS: http://www.jsworkshop.com/bb/viewtopic.php?t=508 |
|
| Back to top |
|
 |
MaartenV New member

Joined: 13 Aug 2002 Posts: 3
|
Posted: Tue Aug 13, 2002 8:11 am Post subject: |
|
|
| YES that was it, you dont want to know how long i searched to find it was fontWeight, i actually tried font-weight like in the ccs. Why are there not more sites that have a full reference for javascript and how you can acces the styles of elements.... |
|
| Back to top |
|
 |
phil karras Senior Member

Joined: 15 Jul 2002 Posts: 1776 Location: MD
|
Posted: Tue Aug 13, 2002 9:25 am Post subject: |
|
|
Probably because there is a standard "conversion" method and JavaScript convention.
The standard naming convention is: always Uppercase the First Letter of the next word in a method name, as in things like: getElementById, etc .
Convert hypenated names to the standard JS convention name. _________________ Phil K
Circle Software Consulting
Test website: http://cs.yrex.com/
Guidelines for Posting: http://www.jsworkshop.com/posting.html
IHBAAA = It Has Been Asked And Answered
KISS: http://www.jsworkshop.com/bb/viewtopic.php?t=508 |
|
| Back to top |
|
 |
mgm Site Admin

Joined: 13 Jul 2002 Posts: 304 Location: Salt Lake City, UT
|
Posted: Tue Aug 13, 2002 10:39 pm Post subject: |
|
|
You don't need the javascript: part in OnMouseOver or other event handlers, they're expected to be JavaScript by default. It works with the javascript: included in IE at least, but I've run into trouble with Netscape.
Also, using 'Bla01.style.fontWeight' is going to be IE-specific since it relies on the 'ID' attribute name being defined as an object. To be really proper it should be something like this:
| Code: |
<script language="JavaScript">
function ChangeWeight(weight) {
obj = document.getElementByID("Bla01");
obj.style.fontWeight=weight;
}
</script>
...
<a href="whatever" ID="Bla01" onmouseover="ChangeWeight('bold');" onmouseout="ChangeWeight('normal');" >
| Of course, if you do it that way, it won't work with IE4 anymore. But that can be done too, it's just more work. _________________ Michael Moncur
Owner and Moderator, The JavaScript Workshop
Read the guidelines before posting: http://www.jsworkshop.com/posting.html |
|
| Back to top |
|
 |
dxvxd Member

Joined: 07 Aug 2002 Posts: 12
|
Posted: Wed Aug 14, 2002 10:27 am Post subject: |
|
|
Maybe this could be a simpler solution, ando you dont need to serch for an object by his id...
<a href="whatever"
onmouseover="this.style.fontWeight='bold'"
onmouseout ="this.style.fontWeight='normal'"> |
|
| Back to top |
|
 |
|