php and javascript problem

I

Irlan agous

I have an echo php link with a javascript mouseout, why doesnt this work?

<a href=\"$PHP_SELF?action=list_records&amp;cur_page=$varray&id=$id\"
onmouseout=javascript:switchColors(this, 'yellow')> $array </a></td>";


Irlan
 
I

Irlan agous

sorry i forget the function is here:
function switchColors(element, color)
{
links=document.getElementsByTagName("a") ;
for (var i = 0 ; i < links.length ; i ++)
links.item(i).style.color = 'blue' ;

element.style.color=color ;
}
 
K

kaeli

I have an echo php link with a javascript mouseout, why doesnt this work?

<a href=\"$PHP_SELF?action=list_records&amp;cur_page=$varray&id=$id\"
onmouseout=javascript:switchColors(this, 'yellow')> $array </a></td>";

Do a view source in the browser to see what is actually written. Post that.

And onmouseout doesn't need "javascript:"
onmouseout=functionName()
not
onmouseout=javascript:functionName()

--
--
~kaeli~
The Bermuda Triangle got tired of warm weather. It moved to
Finland. Now Santa Claus is missing.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace
 
G

Grant Wagner

Irlan agous said:
sorry i forget the function is here:
function switchColors(element, color)
{
links=document.getElementsByTagName("a") ;
for (var i = 0 ; i < links.length ; i ++)
links.item(i).style.color = 'blue' ;

element.style.color=color ;
}

Your function is called switchColors(), you're calling ...
onmouseover="switchColor(this, 'yellow');" ...

You probably want to use -var- to ensure your function variables are
local to the function, and you don't really need item():

function switchColor(element, color)
{
var links = document.getElementsByTagName('a');
for (var ii = 0; ii < links.length; ++ii)
{
links[ii].style.color = 'blue';
}
element.style.color = color;
}

You probably want some appropriate error handling added for browsers
that do no support the methods and properties you are attempting to
access:

function switchColor()
{
return;
}
function switchColorEnabled(element, color)
{
var links = document.getElementsByTagName('a');
for (var ii = 0; ii < links.length; ++ii)
{
links[ii].style.color = 'blue';
}
element.style.color = color;
}
window.onload = function()
{
if (document.getElementsByTagName)
{
var links = document.getElementsByTagName('a');
if (links.length > 0 && links[0].style)
{
switchColor = switchColorEnabled;
}
}
}

I'm still making the assumption that if the first link I retrieve
supports the -style- property, they all will, but I would hope that it's
a fairly safe assumption to make.
 
T

Thomas 'PointedEars' Lahn

Irlan said:
I have an echo php link with a javascript mouseout, why doesnt this work?

Most probably because it does generate invalid HTML.

<a href=\"$PHP_SELF?action=list_records&amp;cur_page=$varray&id=$id\"
onmouseout=javascript:switchColors(this, 'yellow')> $array </a></td>";

Should read

echo <<<EOD
<a
href='${PHP_SELF}?action=list_records&amp;cur_page=${varray}&amp;id=${id}'
onmouseout="switchColors(this, 'yellow')">${array}</a></td>
EOD;

But then,

1. why don't you use forms and submit buttons in the first place?

echo <<<EOD
<form action="list_records">
<input type="hidden" name="cur_page" value="${varray}"
<input type="id" name="cur_page" value="${id}"
<input type="submit">
</form>
EOD;

2. why don't you just use CSS for formatting links hovered on or active?

a:link {
color: black;
background-color: yellow;
}

a:link:hover {
color: yellow;
background-color: black;
}


PointedEars
 
T

Thomas 'PointedEars' Lahn

Irlan said:
sorry i forget the function is here:
function switchColors(element, color)
{
links=document.getElementsByTagName("a") ;

Your method(ology) is flawed since a) not only links are specified with
the `a' element and b) not only the `a' element creates a (hyper)link.

Furthermore, I don't see a test for that host object's method. Don't
assume it is present or you will cause script errors where it is not.

for (var i = 0 ; i < links.length ; i ++)

More efficient would be

for (var i = links.length; i--;)
links.item(i).style.color = 'blue' ;

links.style.color = 'blue';

will suffice according to

<http://www.w3.org/TR/DOM-Level-2-HTML/ecma-script-binding.html>

But text color and background color should never be specified
without the other: said:
element.style.color=color ;

You really want to learn style sheets, namely CSS, ...

}


[Top post]

.... and how to post (in Usenet):

<http://jibbering.com/faq/faq_notes/pots1.html>


PointedEars
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top