SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Addict ketting00's Avatar
    Join Date
    Jul 2011
    Posts
    325
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)

    How to assign source ID dynamically from javascript function

    Hi,

    On the html file I have this code:
    Code:
    <button id='A' onClick='getId(this.id)'>A</button>
    And on the js file I have this code:
    Code:
    function getId(clicked_id) {
    	switch(clicked_id) {
    		case 'A':
    			IdElement = document.getElementById('A');
    		break;
    		case 'B':
    			IdElement = document.getElementById('B');
    		break;
    	}
    }
    Those IdElement come with a click of a button. But what if I want to assign a 'C' id into that the switch function from another javascript function, assuming assignId(), what the code should I compose.

    I want the IdElement come from another function (and it's not a click) when the event is triggered.

    Hope I explain it clearly and thanks in advance.

  2. #2
    SitePoint Addict ketting00's Avatar
    Join Date
    Jul 2011
    Posts
    325
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Never mind I get it done.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •