php and javascript problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Irlan agous

    php and javascript problem

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

    <a href=\"$PHP_SEL F?action=list_r ecords&amp;cur_ page=$varray&id =$id\"
    onmouseout=java script:switchCo lors(this, 'yellow')> $array </a></td>";


    Irlan


  • Irlan agous

    #2
    Re: php and javascript problem

    sorry i forget the function is here:
    function switchColors(el ement, color)
    {
    links=document. getElementsByTa gName("a") ;
    for (var i = 0 ; i < links.length ; i ++)
    links.item(i).s tyle.color = 'blue' ;

    element.style.c olor=color ;
    }


    "Irlan agous" <irlan345@msn.c om> schreef in bericht
    news:b8048$4287 3204$52ade8f3$9 377@news.versat el.nl...[color=blue]
    >I have an echo php link with a javascript mouseout, why doesnt this work?
    >
    > <a href=\"$PHP_SEL F?action=list_r ecords&amp;cur_ page=$varray&id =$id\"
    > onmouseout=java script:switchCo lors(this, 'yellow')> $array </a></td>";
    >
    >
    > Irlan
    >[/color]


    Comment

    • kaeli

      #3
      Re: php and javascript problem

      In article <b8048$42873204 $52ade8f3$9377@ news.versatel.n l>, irlan345@msn.co m
      enlightened us with...[color=blue]
      > I have an echo php link with a javascript mouseout, why doesnt this work?
      >
      > <a href=\"$PHP_SEL F?action=list_r ecords&amp;cur_ page=$varray&id =$id\"
      > onmouseout=java script:switchCo lors(this, 'yellow')> $array </a></td>";
      >[/color]

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

      And onmouseout doesn't need "javascript :"
      onmouseout=func tionName()
      not
      onmouseout=java script:function Name()

      --
      --
      ~kaeli~
      The Bermuda Triangle got tired of warm weather. It moved to
      Finland. Now Santa Claus is missing.



      Comment

      • Grant Wagner

        #4
        Re: php and javascript problem

        "Irlan agous" <irlan345@msn.c om> wrote in message
        news:a3603$4287 342b$52ade8f3$1 0846@news.versa tel.nl...[color=blue]
        > sorry i forget the function is here:
        > function switchColors(el ement, color)
        > {
        > links=document. getElementsByTa gName("a") ;
        > for (var i = 0 ; i < links.length ; i ++)
        > links.item(i).s tyle.color = 'blue' ;
        >
        > element.style.c olor=color ;
        > }
        >
        >
        > "Irlan agous" <irlan345@msn.c om> schreef in bericht
        > news:b8048$4287 3204$52ade8f3$9 377@news.versat el.nl...[color=green]
        >>I have an echo php link with a javascript mouseout, why doesnt this
        >>work?
        >>
        >> <a href=\"$PHP_SEL F?action=list_r ecords&amp;cur_ page=$varray&id =$id\"
        >> onmouseout=java script:switchCo lors(this, 'yellow')> $array
        >> </a></td>";[/color][/color]

        Your function is called switchColors(), you're calling ...
        onmouseover="sw itchColor(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(ele ment, color)
        {
        var links = document.getEle mentsByTagName( 'a');
        for (var ii = 0; ii < links.length; ++ii)
        {
        links[ii].style.color = 'blue';
        }
        element.style.c olor = 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 switchColorEnab led(element, color)
        {
        var links = document.getEle mentsByTagName( 'a');
        for (var ii = 0; ii < links.length; ++ii)
        {
        links[ii].style.color = 'blue';
        }
        element.style.c olor = color;
        }
        window.onload = function()
        {
        if (document.getEl ementsByTagName )
        {
        var links = document.getEle mentsByTagName( 'a');
        if (links.length > 0 && links[0].style)
        {
        switchColor = switchColorEnab led;
        }
        }
        }

        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 <gwagner@agrico reunited.com>
        comp.lang.javas cript FAQ - http://jibbering.com/faq


        Comment

        • Thomas 'PointedEars' Lahn

          #5
          Re: php and javascript problem

          Irlan agous wrote:
          [color=blue]
          > I have an echo php link with a javascript mouseout, why doesnt this work?[/color]

          Most probably because it does generate invalid HTML.

          <http://validator.w3.or g/>
          [color=blue]
          > <a href=\"$PHP_SEL F?action=list_r ecords&amp;cur_ page=$varray&id =$id\"
          > onmouseout=java script:switchCo lors(this, 'yellow')> $array </a></td>";[/color]

          Should read

          echo <<<EOD
          <a
          href='${PHP_SEL F}?action=list_ records&amp;cur _page=${varray} &amp;id=${id }'
          onmouseout="swi tchColors(this, 'yellow')">${ar ray}</a></td>
          EOD;

          But then,

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

          echo <<<EOD
          <form action="list_re cords">
          <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

          Comment

          • Thomas 'PointedEars' Lahn

            #6
            Re: php and javascript problem

            Irlan agous wrote:
            [color=blue]
            > sorry i forget the function is here:
            > function switchColors(el ement, color)
            > {
            > links=document. getElementsByTa gName("a") ;[/color]

            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>
            [color=blue]
            > for (var i = 0 ; i < links.length ; i ++)[/color]

            More efficient would be

            for (var i = links.length; i--;)
            [color=blue]
            > links.item(i).s tyle.color = 'blue' ;[/color]

            links[i].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>
            [color=blue]
            > element.style.c olor=color ;[/color]

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

            <http://www.w3.org/Style/>
            [color=blue]
            > }
            >
            >
            > [Top post][/color]

            .... 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 , <16d1deb5.04022 61008.48f994b6@ posting.google. com>

            Comment

            Working...