...

View Full Version : getElementById-prob



Tuemmel
08-17-2004, 12:03 AM
I've searched your side a while and tried some things out, but nothing will work right.

I've a
js script in the head of the side:
----------------------------------------------------
<script language =javascript>
function newf(i)
{
var element = document.getElementById(i);
element.style.bgcolor='red';
}
</script>
----------------------------------------------------
and a php script that calls the function
----------------------------------------------------
$newcolor ="newf";
{echo "<td width = '18px'align = 'center' bgcolor = '$getit' id =$i name =$i javascript: onmouseover= $newcolor($i)>$dt.<td>";}
}
---------------------------------------------------------------------
but it's not working. The $i is an integer.

do you see the mistake?

sad69
08-17-2004, 01:33 AM
Just a couple of things:
In this PHP code, you've got braces when you don't need them and I dislike the string notation you've used (I like separating the variables from my strings..)


$newcolor ="newf";
echo '<td width="18px" align="center" bgcolor="'.$getit.'" id="'.$i.'" name="'.$i.'" onmouseover="'.$newcolor.'('.$i.')">'.$dt.'.<td>';


Since bgcolor is not a style property, you can't access bgcolor the way you tried. You have a couple of options:

Use element.bgcolor='red'; or element.setAttribute('bgcolor', 'red');
Stop using bgcolor and use background-color / backgroundColor


Without using bgcolor:


echo '<td width="18px" align="center" style="background-color:'.$getit.'" id="'.$i.'" name="'.$i.'" onmouseover="'.$newcolor.'('.$i.')">'.$dt.'.<td>';



<script language =javascript>
function newf(i) {
var element = document.getElementById(i);
element.style.backgroundColor='red';
}
</script>


Hope that helps/works!
Sadiq.

Tuemmel
08-17-2004, 11:09 AM
ok,the php code in the request worked fine. using the code above php was really not interested in first. now it likes it. I made it now like that, following your suggestion.
<?...
if...{
for...{
if...{...}
else{
$newcolor ="newf";
echo '<td width="18px" align="center" style="background-color:'.$getit.'" id="'.$i.'" name="'.$i.'" onmouseover="'.$newcolor.'('.$i.')">'.$dt.'.<td>';}}}
...?>

the prob is the js function. no style or bgcolor changes. but it is called as I can see when I do
"Document.write("<input type = button value =i>")"
, which opens a new side with that button.

<script language =javascript>
function newf(i)
{
//Document.write("<input type = button value =i>") to test
var element = document.getElementById(i);
element.setAttribute('bgcolor', 'red'); //nothing happens ?:)
}
</script>

Tuemmel
08-17-2004, 11:12 AM
that's good. :)
now I'm happy again.

var element = document.getElementById(i);
element.style.backgroundColor='red';

thank you so much sadiq

Kor
08-17-2004, 11:53 AM
You could use setAttribute() method either, but the attribute is bgColor, not bgcolor

element.setAttribute('bgColor','red')



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum