place a link in a button element?

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

    place a link in a button element?

    hey all,

    i have this demo code:

    <script>
    tog=0;
    function setvalue(id){
    if(id){ tog=1
    }else{
    tog=0;
    }
    }

    function cl(){
    if(!tog){
    alert("button clicked")
    }else{
    alert("LINK clicked")
    }
    }
    </script>

    <button value="ee" onclick="cl()">
    I AM A BUTTON <table cellspacing="0" cellpadding="3" border="0"
    height="0" width="0" style="border: 1px;">
    <tr>
    <td>
    <div align="center"> <a href="#" id="test" style=""
    class="test" onmouseover=";s etvalue(1)"
    onmouseout=";se tvalue(0)">link </a></div></td></tr></table>
    </button>

    in a MSI browser it works.. but for mozilla etc not!?

    anybody a solution?

    the <button> element filters all the onclick&onmouse down events in a link :(

    cheers,

    d


  • Erwin Moller

    #2
    Re: place a link in a button element?

    dev wrote:
    [color=blue]
    > hey all,
    >
    > i have this demo code:
    >
    > <script>
    > tog=0;
    > function setvalue(id){
    > if(id){ tog=1
    > }else{
    > tog=0;
    > }
    > }
    >
    > function cl(){
    > if(!tog){
    > alert("button clicked")
    > }else{
    > alert("LINK clicked")
    > }
    > }
    > </script>
    >
    > <button value="ee" onclick="cl()">
    > I AM A BUTTON <table cellspacing="0" cellpadding="3" border="0"
    > height="0" width="0" style="border: 1px;">
    > <tr>
    > <td>
    > <div align="center"> <a href="#" id="test" style=""
    > class="test" onmouseover=";s etvalue(1)"
    > onmouseout=";se tvalue(0)">link </a></div></td></tr></table>
    > </button>
    >
    > in a MSI browser it works.. but for mozilla etc not!?
    >
    > anybody a solution?
    >
    > the <button> element filters all the onclick&onmouse down events in a link
    > :(
    >
    > cheers,
    >
    > d[/color]

    Hi d

    One, of many, problems with M$ Internet Exploder is that it is too
    forgiving, and translates bad script and bad HTML to what it thinks the
    programmer ment.

    Also, when you use Mozilla/NS just check the javascript-console to see what
    the errors are.
    That is what is was made for: a very usefull tool for debugging.

    The first thing I see that is probably causing trouble is:
    onmouseout=";se tvalue(0)"

    that contains 2 mistakes:

    I think you mean:
    onMouseOut="set value(0);"

    what the CaPiTalS and the ;

    (Maybe the script contains more, I didn't check)

    Regards,
    Erwin Moller

    Comment

    • Harag

      #3
      Re: place a link in a button element?

      On Fri, 06 Aug 2004 15:59:53 +0200, Erwin Moller
      <since_humans_r ead_this_I_am_s pammed_too_much @spamyourself.c om> wrote:
      [color=blue]
      >dev wrote:
      >[color=green]
      >> hey all,
      >>
      >> i have this demo code:
      >>
      >> <script>
      >> tog=0;
      >> function setvalue(id){
      >> if(id){ tog=1
      >> }else{
      >> tog=0;
      >> }
      >> }
      >>
      >> function cl(){
      >> if(!tog){
      >> alert("button clicked")
      >> }else{
      >> alert("LINK clicked")
      >> }
      >> }
      >> </script>
      >>
      >> <button value="ee" onclick="cl()">
      >> I AM A BUTTON <table cellspacing="0" cellpadding="3" border="0"
      >> height="0" width="0" style="border: 1px;">
      >> <tr>
      >> <td>
      >> <div align="center"> <a href="#" id="test" style=""
      >> class="test" onmouseover=";s etvalue(1)"
      >> onmouseout=";se tvalue(0)">link </a></div></td></tr></table>
      >> </button>
      >>
      >> in a MSI browser it works.. but for mozilla etc not!?
      >>
      >> anybody a solution?
      >>
      >> the <button> element filters all the onclick&onmouse down events in a link
      >> :(
      >>
      >> cheers,
      >>
      >> d[/color]
      >
      >Hi d
      >
      >One, of many, problems with M$ Internet Exploder is that it is too
      >forgiving, and translates bad script and bad HTML to what it thinks the
      >programmer ment.
      >
      >Also, when you use Mozilla/NS just check the javascript-console to see what
      >the errors are.
      >That is what is was made for: a very usefull tool for debugging.
      >
      >The first thing I see that is probably causing trouble is:
      >onmouseout=";s etvalue(0)"
      >
      >that contains 2 mistakes:
      >
      >I think you mean:
      >onMouseOut="se tvalue(0);"
      >
      >what the CaPiTalS and the ;
      >
      >(Maybe the script contains more, I didn't check)
      >
      >Regards,
      >Erwin Moller[/color]

      You don't need capitals under the HTML attributes as they are case
      INsensitive, just onclick= or onmouseover or onsubmit etc is fine.

      The main problem is defining all the html code in the
      <button></button> tags. I think only plain text "click me" is allowed
      there,

      HTH

      Al.



      Comment

      • Michael Winter

        #4
        Re: place a link in a button element?

        On Sat, 07 Aug 2004 12:15:06 +0100, Harag <haragREMOVECAP S@softhome.com>
        wrote:

        [snip]
        [color=blue]
        > The main problem is defining all the html code in the
        > <button></button> tags. I think only plain text "click me" is allowed
        > there,[/color]

        You're allowed a *lot* more than that. The BUTTON element is extremely
        versatile. I think the only reason why it isn't use much is because older
        browsers don't support it.

        According to the DTD, the only elements that *aren't* allowed as content
        for the button are A, FORM, FIELDSET and form controls. That shows just
        how flexible the element is. However, it's clear that the OP is writing
        invalid HTML because the button does contain a disallowed element.

        To the OP:

        If you're having trouble, it's often worth validating your HTML. Had you
        done so, you'd have immediately found that your document is invalid. See
        <URL:http://validator.w3.or g/>.

        Mike

        --
        Michael Winter
        Replace ".invalid" with ".uk" to reply by e-mail

        Comment

        • Richard Cornford

          #5
          Re: place a link in a button element?

          Michael Winter wrote:
          <snip>[color=blue]
          > ... . I think the only reason why it isn't use much is
          > because older browsers don't support it.[/color]
          <snip>

          Another problem that must often make the BUTTON element seem unreliable
          is its default type. With the W3C specifying it as defaulting to
          type="submit" and Microsoft deciding to default to type="button".
          Browser manufactures what to follow the W3C specs, but it can be as
          important to them to follow IE (or look broken to the uniformed) so how
          the BUTTON will default is completely up in the air.

          Conclusion: If BUTTON is used it should have its TYPE attribute
          explicitly set, even though the validators will not require that.

          So when you read: "in a MSI browser it works.. but for mozilla etc
          not!?" and see a button with no TYPE attribute (even one that is
          apparently not in a FORM) then that is another factor that can explain
          the observation.

          Richard.


          Comment

          • me

            #6
            Re: place a link in a button element?

            Hey all,

            Wel i know about define the type="submit" etc etc
            but mine boss wanted a button element and inside a link with different
            target,
            So i made up this script that worked.. even in mozilla i can use different
            style sheets atributtes and it works only no events are alowed in
            firefox-mozilla for the child-elements inside the buttontag..i think.. ;)

            so there is no work around it?
            yust being curious,

            Cheers and thanks all for ur replay on this subject.

            D,

            "Richard Cornford" <Richard@litote s.demon.co.uk> wrote in message
            news:cf2ide$lko $1$830fa17d@new s.demon.co.uk.. .[color=blue]
            > Michael Winter wrote:
            > <snip>[color=green]
            > > ... . I think the only reason why it isn't use much is
            > > because older browsers don't support it.[/color]
            > <snip>
            >
            > Another problem that must often make the BUTTON element seem unreliable
            > is its default type. With the W3C specifying it as defaulting to
            > type="submit" and Microsoft deciding to default to type="button".
            > Browser manufactures what to follow the W3C specs, but it can be as
            > important to them to follow IE (or look broken to the uniformed) so how
            > the BUTTON will default is completely up in the air.
            >
            > Conclusion: If BUTTON is used it should have its TYPE attribute
            > explicitly set, even though the validators will not require that.
            >
            > So when you read: "in a MSI browser it works.. but for mozilla etc
            > not!?" and see a button with no TYPE attribute (even one that is
            > apparently not in a FORM) then that is another factor that can explain
            > the observation.
            >
            > Richard.
            >
            >[/color]


            Comment

            • Michael Winter

              #7
              Re: place a link in a button element?

              On Sat, 7 Aug 2004 15:33:48 +0200, me <someone@micros oftnospam.com> wrote:
              [color=blue]
              > Wel i know about define the type="submit" etc etc
              > but mine boss wanted a button element and inside a link withdifferent
              > target,[/color]

              Well, I'd tell your boss that it's nonsense. The BUTTON element simply
              needs to render the contents, not allow interaction with them. If you
              notice, most (if not all) interactive elements - A and all form controls -
              are forbidden within a BUTTON, so why would a browser developer waste time
              implementing any interaction?
              [color=blue]
              > So i made up this script that worked.. even in mozilla i can use
              > different style sheets atributtes and it works only no events arealowed
              > in firefox-mozilla for the child-elements inside thebuttontag..i
              > think.. ;)[/color]

              Most likely because of the reasons I just mentioned. By the way, it isn't
              just Mozilla that exhibits this behaviour.
              [color=blue]
              > so there is no work around it?[/color]

              No, and I don't think there should be. It's invalid HTML, and you
              shouldn't expect any scripts to work properly in such circumstances.
              That's why this group advocates validation.

              [snip]

              Mike

              --
              Michael Winter
              Replace ".invalid" with ".uk" to reply by e-mail

              Comment

              • me

                #8
                Re: place a link in a button element?

                Hey Michael,

                wel its is kind of complex because of the interface once made..
                so it would work out :)
                i did 4 tricks
                - only MSI :P
                - make a custom image and make a maparea and with PHP-GD i write mine
                adusted link text and set the javascript map area event
                - i made flash buttons :)
                - i program mine own browser that i offer free to download every time a new
                user is on the site :)
                ok it is the best to use a images ;)


                "Michael Winter" <M.Winter@bluey onder.co.invali d> wrote in message
                news:opscdee0iy x13kvk@atlantis ...[color=blue]
                > On Sat, 7 Aug 2004 15:33:48 +0200, me <someone@micros oftnospam.com> wrote:
                >[color=green]
                > > Wel i know about define the type="submit" etc etc
                > > but mine boss wanted a button element and inside a link withdifferent
                > > target,[/color]
                >
                > Well, I'd tell your boss that it's nonsense. The BUTTON element simply
                > needs to render the contents, not allow interaction with them. If you
                > notice, most (if not all) interactive elements - A and all form controls -
                > are forbidden within a BUTTON, so why would a browser developer waste time
                > implementing any interaction?
                >[color=green]
                > > So i made up this script that worked.. even in mozilla i can use
                > > different style sheets atributtes and it works only no events arealowed
                > > in firefox-mozilla for the child-elements inside thebuttontag..i
                > > think.. ;)[/color]
                >
                > Most likely because of the reasons I just mentioned. By the way, it isn't
                > just Mozilla that exhibits this behaviour.
                >[color=green]
                > > so there is no work around it?[/color]
                >
                > No, and I don't think there should be. It's invalid HTML, and you
                > shouldn't expect any scripts to work properly in such circumstances.
                > That's why this group advocates validation.
                >
                > [snip]
                >
                > Mike
                >
                > --
                > Michael Winter
                > Replace ".invalid" with ".uk" to reply by e-mail[/color]


                Comment

                • Harag

                  #9
                  Re: place a link in a button element?

                  On Sat, 07 Aug 2004 11:59:59 GMT, "Michael Winter"
                  <M.Winter@bluey onder.co.invali d> wrote:
                  [color=blue]
                  >On Sat, 07 Aug 2004 12:15:06 +0100, Harag <haragREMOVECAP S@softhome.com>
                  >wrote:
                  >
                  >[snip]
                  >[color=green]
                  >> The main problem is defining all the html code in the
                  >> <button></button> tags. I think only plain text "click me" is allowed
                  >> there,[/color]
                  >
                  >You're allowed a *lot* more than that. The BUTTON element is extremely
                  >versatile. I think the only reason why it isn't use much is because older
                  >browsers don't support it.
                  >
                  >According to the DTD, the only elements that *aren't* allowed as content
                  >for the button are A, FORM, FIELDSET and form controls. That shows just
                  >how flexible the element is. However, it's clear that the OP is writing
                  >invalid HTML because the button does contain a disallowed element.[/color]


                  Really? cool thanks for that, I never really used the <button> tags as
                  I always thought that it was an "older version" of using <input
                  type="button"> I'll now have to look into the <button> tags.

                  Thanks.

                  AL

                  [snip]

                  Comment

                  Working...