php and javascript problem

Discussion in 'Javascript' started by Irlan agous, May 15, 2005.

  1. Irlan agous

    Irlan agous Guest

    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
    Irlan agous, May 15, 2005
    #1
    1. Advertising

  2. Irlan agous

    Irlan agous Guest

    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 ;
    }


    "Irlan agous" <> schreef in bericht
    news:b8048$42873204$52ade8f3$...
    >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
    >
    Irlan agous, May 15, 2005
    #2
    1. Advertising

  3. Irlan agous

    kaeli Guest

    In article <b8048$42873204$52ade8f3$>,
    enlightened us with...
    > 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
    kaeli, May 16, 2005
    #3
  4. Irlan agous

    Grant Wagner Guest

    "Irlan agous" <> wrote in message
    news:a3603$4287342b$52ade8f3$...
    > 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 ;
    > }
    >
    >
    > "Irlan agous" <> schreef in bericht
    > news:b8048$42873204$52ade8f3$...
    >>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>";


    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.

    --
    Grant Wagner <>
    comp.lang.javascript FAQ - http://jibbering.com/faq
    Grant Wagner, May 17, 2005
    #4
  5. Irlan agous wrote:

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


    Most probably because it does generate invalid HTML.

    <http://validator.w3.org/>

    > <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
    Thomas 'PointedEars' Lahn, May 23, 2005
    #5
  6. Irlan agous wrote:

    > 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.

    <http://pointedears.de/scripts/test/whatami>

    > 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: <http://www.w3.org/QA/Tips/color>

    > element.style.color=color ;


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

    <http://www.w3.org/Style/>

    > }
    >
    >
    > [Top post]


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

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


    PointedEars
    --
    Germany is the birth place of psychiatry. Psychs feel threatened by
    Scientology as they are crazy. Many psychs become psychs to heal their own
    mental problems and to control others. -- "The only real Barbara Schwarz",
    dsw.scientology, <>
    Thomas 'PointedEars' Lahn, May 23, 2005
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ted Zeng
    Replies:
    4
    Views:
    474
    Tim Arnold
    Oct 3, 2006
  2. Rajive Narain
    Replies:
    0
    Views:
    1,542
    Rajive Narain
    Sep 18, 2009
  3. eastcoastguyz
    Replies:
    1
    Views:
    93
    Flamer
    Jul 11, 2006
  4. Replies:
    3
    Views:
    187
    frothpoker
    Sep 4, 2006
  5. __
    Replies:
    1
    Views:
    107
    Gregor Kofler
    Oct 2, 2007
Loading...

Share This Page