Page 1 of 1

onMouseOver with PHP = how?

Posted: Fri May 14, 2010 5:43 am
by simonmlewis

Code: Select all

 if ($row->status == "on hold") { echo "
      <tr bgcolor='#FFCF00' onMouseOver=\"this.bgColor='#FFCF00';\" onMouseOut=\"this.bgColor='#FFCF00';\">
      "; }
      
      elseif ($row->status == NULL) { echo "
      <tr bgcolor='#ffffff' onMouseOver=\"this.bgColor='#E7E7E7';\" onMouseOut=\"this.bgColor='#FFFFFF';\">
      "; }
This products the highlighted #FFCF00 and keeps it highlighted when you hover over. But none of the other fields go grey.
This on it's own....

Code: Select all

<tr bgcolor='#ffffff' onMouseOver=\"this.bgColor='#E7E7E7';\" onMouseOut=\"this.bgColor='#FFFFFF';\">
.... works.

So what's wrong with the If statement? I am sure it is something to do with the " and ' (from a previous post about this, I could understand), but it appears fine to me.

It's meant to highlight the row light grey on hover(mouseover), but for those 'on hold' it should stay orange.

Re: onMouseOver with PHP = how?

Posted: Fri May 14, 2010 6:26 am
by cpetercarter
The problem may lie in your "elseif" statement. Are you sure that the right condition is $row->status == NULL and not, for example, $row->status == "" ?

Code: Select all

if (empty($row->status))
would catch $row->status == NULL and $row->status == false and $row->status == "".

Re: onMouseOver with PHP = how?

Posted: Fri May 14, 2010 6:30 am
by simonmlewis
Yes I am, as the field only has content or NULL.

I've just sussed it. Trying ....
} else {
rather than
} elseif {

works!!

Code: Select all

            if ($row->status == "on hold") { echo "
      <tr bgcolor='#FFCF00' onMouseOver=\"this.bgColor='#FFCF00';\" onMouseOut=\"this.bgColor='#FFCF00';\">
      "; }
      
      else { echo "
      <tr bgcolor='#FFFFFF' onMouseOver=\"this.bgColor='#E7E7E7';\" onMouseOut=\"this.bgColor='#FFFFFF';\">
      "; }

Re: onMouseOver with PHP = how?

Posted: Fri May 14, 2010 8:05 am
by cpetercarter
I am glad you have sorted this problem. However, it cannot be the case that $row->status is either "on hold" or NULL, because if that were so your original code would have worked. Perhaps a form submission, or some other action in your script, has given rows which are not "on hold" a value, perhaps "" or 'false'.