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. setAttribute property in javascript

setAttribute property in javascript

Scheduled Pinned Locked Moved ASP.NET
javascriptquestion
13 Posts 5 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 Sun Rays

    SamRST wrote:

    // txtC.setAttribute("onClick","alert('Ok')");//this is not working

    Chage it... txtC.onClick = function MyClick() {alert('Ok');} Hi, Hope u ll get it.

    Thanks, Sun Rays To get something you must have to try once. My Articles

    modified on Friday, May 9, 2008 1:38 AM

    S Offline
    S Offline
    SamRST
    wrote on last edited by
    #4

    i cannot do this in pageload event, bcose i'm creating adding this control dynamic (no page reloading).

    1 Reply Last reply
    0
    • S Spunky Coder

      use the following txtC.Attributes.Add("onClick", "javascript:alert('Ok')");

      .....

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

      i want to bind the event, when its created.. not in the pageload. bcose its creating dyn using javascript...

      1 Reply Last reply
      0
      • S SamRST

        hi.. i'm creating textboxes and imgebttn dynamically inside a table using javascript. i set some properties for the textboxes. but how can i bind 'onclick' events to the button. The code i used is below. //for textbox var txtA=document.createElement("input"); txtA.type = 'text'; txtA.id ='a'+lastrowIndex; txtA.name ='a'+lastrowIndex; txtA.className='textbox'; txtA.readonly='readonly'; //for imgbtn var txtC=document.createElement("img"); txtC.id ='c'+lastrowIndex; txtC.name ='c'+lastrowIndex; txtC.className='images_del'; txtC.src="Images/delete_16x16.gif"; // txtC.setAttribute("onClick","alert('Ok')");//this is not working Thanks in advance.

        C Offline
        C Offline
        Christian Graus
        wrote on last edited by
        #6

        What's wrong with txtC.onclick = "alert('OK');" ???

        Christian Graus Please read this if you don't understand the answer I've given you "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

        S 1 Reply Last reply
        0
        • C Christian Graus

          What's wrong with txtC.onclick = "alert('OK');" ???

          Christian Graus Please read this if you don't understand the answer I've given you "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

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

          there z no error, but event is not firing.. !!!

          C 1 Reply Last reply
          0
          • S SamRST

            there z no error, but event is not firing.. !!!

            C Offline
            C Offline
            Christian Graus
            wrote on last edited by
            #8

            I believe it's meant to be all lowercase

            Christian Graus Please read this if you don't understand the answer I've given you "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

            S 1 Reply Last reply
            0
            • C Christian Graus

              I believe it's meant to be all lowercase

              Christian Graus Please read this if you don't understand the answer I've given you "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

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

              what all i tried is. txtC.setAttribute("onClick","alert('Ok')"); txtC.setAttribute("onclick","alert('Ok')"); txtC.setAttribute("onClick", "javascript:alert(this.id);"); txtC.setAttribute("onclick", "javascript:alert(this.id);"); txtC.onClick = "javascript:alert(this.id);"; txtC.onclick = "javascript:alert(this.id);"; txtC.onclick = "javascript:alert('Ok');";

              S W 2 Replies Last reply
              0
              • S SamRST

                what all i tried is. txtC.setAttribute("onClick","alert('Ok')"); txtC.setAttribute("onclick","alert('Ok')"); txtC.setAttribute("onClick", "javascript:alert(this.id);"); txtC.setAttribute("onclick", "javascript:alert(this.id);"); txtC.onClick = "javascript:alert(this.id);"; txtC.onclick = "javascript:alert(this.id);"; txtC.onclick = "javascript:alert('Ok');";

                S Offline
                S Offline
                Spunky Coder
                wrote on last edited by
                #10

                Has to use event handler ... txtC.onclick=doSomething; function doSomething(e) { alert('Ok'); }

                .....

                S 1 Reply Last reply
                0
                • S Spunky Coder

                  Has to use event handler ... txtC.onclick=doSomething; function doSomething(e) { alert('Ok'); }

                  .....

                  S Offline
                  S Offline
                  SamRST
                  wrote on last edited by
                  #11

                  Thanks You So much my lovely GUY... Its Worked... Great work.. Dear... i used ... txtC.onclick = function(){ImageId(this.id);}; function ImageId(i) { alert(i); }

                  S 1 Reply Last reply
                  0
                  • S SamRST

                    Thanks You So much my lovely GUY... Its Worked... Great work.. Dear... i used ... txtC.onclick = function(){ImageId(this.id);}; function ImageId(i) { alert(i); }

                    S Offline
                    S Offline
                    Spunky Coder
                    wrote on last edited by
                    #12

                    Cheers :)

                    .....

                    1 Reply Last reply
                    0
                    • S SamRST

                      what all i tried is. txtC.setAttribute("onClick","alert('Ok')"); txtC.setAttribute("onclick","alert('Ok')"); txtC.setAttribute("onClick", "javascript:alert(this.id);"); txtC.setAttribute("onclick", "javascript:alert(this.id);"); txtC.onClick = "javascript:alert(this.id);"; txtC.onclick = "javascript:alert(this.id);"; txtC.onclick = "javascript:alert('Ok');";

                      W Offline
                      W Offline
                      webtips
                      wrote on last edited by
                      #13

                      have you tried this var ele = document.getElementById('abc'); ele.onclick = showalert; function showalert() { alert('a'); } -------------------- Check my other javascript posts

                      Regards, Webtips - Web Development tips

                      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