#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Posts
    21
    Rep Power
    0

    How to tell if the button is clicked


    Hi,

    Alert shows me the value of each button, but how can I get the value of each button then do what I need to do just my example below?
    thanks

    <button id="1" onClick="reply_click(this.id)">B1</button>
    <button id="2" onClick="reply_click(this.id)">B2</button>
    <button id="3" onClick="reply_click(this.id)">B3</button>

    <script type="text/javascript">
    function reply_click(clicked_id)
    {
    alert(clicked_id);
    }
    </script>

    <Cfif id eq 1>
    show this.....
    <cfelse>
    ....
    </Cfif>
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2013
    Posts
    26
    Rep Power
    0
    Code:
    <!DOCTYPE HTML>
    <html>
    <head>
    <title> Untitled </title>
    <meta charset="utf-8">
    
    <style type="text/css">
    
    </style>
    
    </head>
    <body>
    
     <button id="b1" onClick="reply_click(this)"> Button1 </button>
     <button id="b2" onClick="reply_click(this)"> Button2 </button>
     <button id="b3" onClick="reply_click(this)"> Button3 </button>
    
     <script type="text/javascript">
     function reply_click(clicked){
     	alert(clicked.id);
    	clicked.innerHTML="Clicked"
     }
     </script>
    
    </body>
    </html>
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Posts
    21
    Rep Power
    0
    thank you, but I am not sure what you are try to show me, all I see is the button is changed from Button1 to Clicked, but is there the way to get the value out from the function?
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2013
    Posts
    26
    Rep Power
    0
    Code:
    <!DOCTYPE HTML>
    <html>
    <head>
    <title> Untitled </title>
    <meta charset="utf-8">
    <style type="text/css">
    </style>
    </head>
    <body>
     <button onClick="reply_click(this)"> Button1 </button>
     <button onClick="reply_click(this)"> Button2 </button>
     <button onClick="reply_click(this)"> Button3 </button>
     <input id="dsply">
     <script type="text/javascript">
     function reply_click(clicked){
    	dsply.value = clicked.innerHTML;
    	
     }
     </script>
    </body>
    </html>

IMN logo majestic logo threadwatch logo seochat tools logo