Javascript: Get Element ID


I'm trying to get the ID of an element.

So for example when my textboxes get generated the look something like this:

<input id="ctl00_ContentPlaceHolder1_R0C3" onclick="javascript:GetId(this)" />

And then I have the following javascript:

function GetId(textbox)
     var id =;
     alert('ID: ' + id);  //This works
     alert('ID: ' + id.substring(27));  //This does not work

What I want is to take the ID, and trim off the "ctl00_ContentPlaceHolder1_" so that all I'm left with is "ROC3" held in a variable that I can then continue to do other stuff with in code.
LVL 10
Who is Participating?
P1ST0LPETEConnect With a Mentor Author Commented:
Figured it out:

Just needed to add ".toString()" into the mix:

so alert('ID: ' + id.toString().substring(27));  works like a charm.
erikTsomikSystem Architect, CF programmer Commented:
can you simply do this getElementById
P1ST0LPETEAuthor Commented:

I should have said: I'm trying to get the ID of an element, modify it, and hold it in a variable.
P1ST0LPETEAuthor Commented:
"can you simply do this getElementById"

Well I already know what the element is..........Im passing it in as a parameter for the function.

I'm trying to get the value of the ID, so that I can parse it down to "R0C3", which is telling myself what row and column [of a table] the textbox is in, because I need to grab other values from the same row.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.