Help - Search - Members - Calendar
Full Version: Help with JavaScript onmouseover
HTMLHelp Forums > Programming > Server-side Scripting
JustinC474
Im currently trying to program a table such that when you mouse over a cell, it changes color. I include a .js file into my php class then it is called through my index.php.

so index.php makes a $table object
then i call $table->displayTable()

here is that codefunction

displayTable()
{
echo '<table class = "halloween" border = "1">';
echo '<script type = "txt/javascript"> src = "java_script.js"></script>';
echo '<tr>';
foreach($this->columns as $header => $order)
{
echo '<th>';
echo $header;
echo '</th>';
}
for($i = 0; $i < $this->numRows; $i++)
{
echo '<tr>';
foreach($this->data[$i] as $value)
{
echo '<td onmousover = "alert(this)" onmouseout = "ParaOut(this)">';
if($value!="")
echo $value;
else
echo '<input type = "text" name = "information" size = 10>';
echo '</td>';
}
echo '</tr>';
}
echo '</table>';
}

this calls javascript.js which is here

function test(value)
{
alert("boring");
alert(value);
}

var ColorCode = new Array("eof1ee", "d6efff", "646560", "ffffcc", "66ccff", "99\
ffcc", "c0c0c0", "669999");

function ParaOver(CaoPhong)
{
CaoPhong.style.backgroundColor = ColorCode[Math.round(Math.random()*10)];
}

function ParaOut(CaoPhong)
{
CaoPhong.style.backgroundColor = "transparent";
}

and nothing happens. any idea how i can get the cells to change color on mouse over? this is my first week ever programming PHP HTML or JavaScript (for an internship) so any veteran advice would be greatly appreciated

thanks
Frederiek
I haven't tried your code, but you have:
echo '<script type = "txt/javascript"> src = "java_script.js"></script>';

which should be:
echo '<script type="text/javascript" src="java_script.js"></script>';
JustinC474
Thanks, im sure if it wasnt causing errors that was bound to. Another thing I find interesting is in the line

echo '<td onmousover = "ParaOver(this)" onmouseout = "ParaOut(this)">';

if i change it to

echo '<td onclick = "alert(this)" onmousover = "ParaOver(this)" onmouseout = "ParaOut(this)">';

the onclick works, which tells me that it must be in ParaOver() and ParaOut() EXCEPT if i change it to

echo '<td onclick = "alert(this)" onmousover = "alert(this)" onmouseout = "alert(this)">';

still nothing happens on a mouse over, so it must be something having to do with the onmouseover and onmouseout and how the interact with the <td></td> tag
JustinC474
and to make this even more interesting....


echo '<td onclick = "ParaOver(this)" onmousover = "ParaOver(this)" onmouseout = "ParaOut(this)">';

the onclick works (making it change color) and then the onmouseout works (changing it back). but the onmouseover is still the only fnc not working.... thoughts?
pandy
Maybe you could post the link to a sample page with the actual script and all?
Christian J
Do you spell it "onmousover" in the actual code?
pandy
laugh.gif
JustinC474
fucking *beep* i has onmousover missed an e

thanks for the tip
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.