troubleshooting Question

Javascript: Get Element ID

Avatar of P1ST0LPETE
P1ST0LPETEFlag for United States of America asked on
JavaScript
4 Comments1 Solution907 ViewsLast Modified:
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.
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 4 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros