Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. use javascript to change the color for mouseover

use javascript to change the color for mouseover

Scheduled Pinned Locked Moved ASP.NET
javascripttutorialquestion
14 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Seraph_summer

    after I get the id of the linkbutton (as follows), then how to change the backcolor of the button I do not know which function can be used. function LinkBtnMouseOver() { var LinkClientID = "<%=LinkButton1.ClientID%>"; var NewID = document.getElementById(LinkClientID); ? } thanks.

    S Offline
    S Offline
    sajjy
    wrote on last edited by
    #5

    oops my text came half !!! :-D and add this one to java script:

    NewID.style.backgroundColor = 'yourcolor';

    S 1 Reply Last reply
    0
    • S sajjy

      oops my text came half !!! :-D and add this one to java script:

      NewID.style.backgroundColor = 'yourcolor';

      S Offline
      S Offline
      Seraph_summer
      wrote on last edited by
      #6

      thanks, unfortunately, no .style is supported by NewID. it is strange that you can use .style?? I am using visual web developer 2008 express. oh, unbelievable, when I type NewID.style.backgroundColor ="Blue", it does work! but strange is that: when I type NewID. then all the functions within NewID should be automatically appear, but .style can not be found anyway. do you know the reason? a bug or sth else?

      S 1 Reply Last reply
      0
      • S Seraph_summer

        thanks, unfortunately, no .style is supported by NewID. it is strange that you can use .style?? I am using visual web developer 2008 express. oh, unbelievable, when I type NewID.style.backgroundColor ="Blue", it does work! but strange is that: when I type NewID. then all the functions within NewID should be automatically appear, but .style can not be found anyway. do you know the reason? a bug or sth else?

        S Offline
        S Offline
        sajjy
        wrote on last edited by
        #7

        :laugh: yes i know it`s like this ;) i have visual studio enterprise , and it`s not supported very well here too !:mad: but i think that on express mode many of features are not working :suss: i think that just some stupid coder like me can Use these old "dhtml" commands ! but any how i love dhtml an i use it any where ;P

        S 1 Reply Last reply
        0
        • S sajjy

          :laugh: yes i know it`s like this ;) i have visual studio enterprise , and it`s not supported very well here too !:mad: but i think that on express mode many of features are not working :suss: i think that just some stupid coder like me can Use these old "dhtml" commands ! but any how i love dhtml an i use it any where ;P

          S Offline
          S Offline
          Seraph_summer
          wrote on last edited by
          #8

          thanks, further question, as you know, I can solve this problem as follows, but I have many linkbuttons, should I write different funcitons for different buttons, because the button ID is used in the funcitons, how can I write one common function which can be used by all buttons by passing the ID or sth else? function LinkBtnMouseOver() { var LinkClientID = "<%=LinkButton1.ClientID%>"; var NewID = document.getElementById(LinkClientID); NewID.style.backgroundColor = "Blue"; } function LinkBtnMouseOut(obj) { var LinkClientID = "<%=LinkButton1.ClientID%>"; var NewID = document.getElementById(LinkClientID); NewID.style.backgroundColor = "Green"; }

          S 1 Reply Last reply
          0
          • S Seraph_summer

            thanks, further question, as you know, I can solve this problem as follows, but I have many linkbuttons, should I write different funcitons for different buttons, because the button ID is used in the funcitons, how can I write one common function which can be used by all buttons by passing the ID or sth else? function LinkBtnMouseOver() { var LinkClientID = "<%=LinkButton1.ClientID%>"; var NewID = document.getElementById(LinkClientID); NewID.style.backgroundColor = "Blue"; } function LinkBtnMouseOut(obj) { var LinkClientID = "<%=LinkButton1.ClientID%>"; var NewID = document.getElementById(LinkClientID); NewID.style.backgroundColor = "Green"; }

            S Offline
            S Offline
            sajjy
            wrote on last edited by
            #9

            ex me because it`s late night here , and i must go to bed ;) you can use something like this :

            link button

            and change yur javascript to this mode :

            function LinkBtnMouseOver(e) {
            document.getElementById(e).style.backgroundColor = 'Blue';
            }

            function LinkBtnMouseOut(e) {
            document.getElementById(e).style.backgroundColor = 'Green';
            }

            or maybe it works directly on your asp page totaly like this new one : :sigh:

            <asp:LinkButton ID="LinkButton1" runat="server" onmouseover="this.style.backgroundColor = 'Blue';" onmouseout="this.style.backgroundColor = 'Green';">link button

            hope that it works :rolleyes:

            S 1 Reply Last reply
            0
            • S sajjy

              ex me because it`s late night here , and i must go to bed ;) you can use something like this :

              link button

              and change yur javascript to this mode :

              function LinkBtnMouseOver(e) {
              document.getElementById(e).style.backgroundColor = 'Blue';
              }

              function LinkBtnMouseOut(e) {
              document.getElementById(e).style.backgroundColor = 'Green';
              }

              or maybe it works directly on your asp page totaly like this new one : :sigh:

              <asp:LinkButton ID="LinkButton1" runat="server" onmouseover="this.style.backgroundColor = 'Blue';" onmouseout="this.style.backgroundColor = 'Green';">link button

              hope that it works :rolleyes:

              S Offline
              S Offline
              sajjy
              wrote on last edited by
              #10

              one other thing ;) if you found my postes helpful rate them !!! :-D

              S 1 Reply Last reply
              0
              • S Seraph_summer

                after I get the id of the linkbutton (as follows), then how to change the backcolor of the button I do not know which function can be used. function LinkBtnMouseOver() { var LinkClientID = "<%=LinkButton1.ClientID%>"; var NewID = document.getElementById(LinkClientID); ? } thanks.

                A Offline
                A Offline
                Abhishek Sur
                wrote on last edited by
                #11

                Why do you need javascript when there is no need. Javascript is slower than actual CSS AFAIK. Just a simple fix for you. In Head section Add

                <style type="text/css">
                .lnk
                {
                	background-color:Green;
                }
                .lnk:hover
                {
                	background-color:Aqua;
                }
                </style>
                

                Now inside Form create these

                <asp:LinkButton CssClass="lnk" runat="server" >This is link
                </asp:LinkButton>

                Now see it should be working. Make appropriate alteration on the CSS. :rose::rose:

                Abhishek Sur


                My Latest Articles **Create CLR objects in SQL Server 2005 C# Uncommon Keywords Read/Write Excel using OleDB

                **Don't forget to click "Good Answer" if you like to.

                S 1 Reply Last reply
                0
                • S sajjy

                  one other thing ;) if you found my postes helpful rate them !!! :-D

                  S Offline
                  S Offline
                  Seraph_summer
                  wrote on last edited by
                  #12

                  thank you very much! I have rated 5!

                  1 Reply Last reply
                  0
                  • A Abhishek Sur

                    Why do you need javascript when there is no need. Javascript is slower than actual CSS AFAIK. Just a simple fix for you. In Head section Add

                    <style type="text/css">
                    .lnk
                    {
                    	background-color:Green;
                    }
                    .lnk:hover
                    {
                    	background-color:Aqua;
                    }
                    </style>
                    

                    Now inside Form create these

                    <asp:LinkButton CssClass="lnk" runat="server" >This is link
                    </asp:LinkButton>

                    Now see it should be working. Make appropriate alteration on the CSS. :rose::rose:

                    Abhishek Sur


                    My Latest Articles **Create CLR objects in SQL Server 2005 C# Uncommon Keywords Read/Write Excel using OleDB

                    **Don't forget to click "Good Answer" if you like to.

                    S Offline
                    S Offline
                    Seraph_summer
                    wrote on last edited by
                    #13

                    have you tried by yourself? anyway, it does not work for my case, that's why I am looking for other methods.

                    A 1 Reply Last reply
                    0
                    • S Seraph_summer

                      have you tried by yourself? anyway, it does not work for my case, that's why I am looking for other methods.

                      A Offline
                      A Offline
                      Abhishek Sur
                      wrote on last edited by
                      #14

                      Yes .. I did check myself. I have already replied to some other guy in this forum about this. If you need me to send you the web page which render this, I can do that.:rose:

                      Abhishek Sur


                      My Latest Articles **Create CLR objects in SQL Server 2005 C# Uncommon Keywords Read/Write Excel using OleDB

                      **Don't forget to click "Good Answer" if you like to.

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups