Javascript: Get Element ID

Hi,

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 = textbox.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
P1ST0LPETEAsked:
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.
0
 
erikTsomikSystem Architect, CF programmer Commented:
can you simply do this getElementById
0
 
P1ST0LPETEAuthor Commented:
Correction:

I should have said: I'm trying to get the ID of an element, modify it, and hold it in a variable.
0
 
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.
0
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.