javascript string manipulation

Discussion in 'ASP .Net' started by rodchar, Apr 9, 2008.

  1. rodchar

    rodchar Guest

    hey all,
    what's the best way to extract info from the following string:

    controlvalueid_ctl02_DrpX

    i need "_Drp" and everything to the right of it.

    thanks,
    rodchar
     
    rodchar, Apr 9, 2008
    #1
    1. Advertising

  2. rodchar

    bruce barker Guest

    var s = 'controlvalueid_ctl02_DrpX'.match(/_Drp.*$/)

    -- bruce (sqlwork.com)


    "rodchar" wrote:

    > hey all,
    > what's the best way to extract info from the following string:
    >
    > controlvalueid_ctl02_DrpX
    >
    > i need "_Drp" and everything to the right of it.
    >
    > thanks,
    > rodchar
     
    bruce barker, Apr 9, 2008
    #2
    1. Advertising

  3. rodchar

    rodchar Guest

    yes Mark but this is the only way i know to get it thru javascript. is there
    another way?

    "Mark Rae [MVP]" wrote:

    > "rodchar" <> wrote in message
    > news:...
    >
    > > what's the best way to extract info from the following string:
    > >
    > > controlvalueid_ctl02_DrpX
    > >
    > > i need "_Drp" and everything to the right of it.

    >
    > Are you trying to find the server-side control ID, as opposed to the
    > "munged" client-side control ID...?
    >
    >
    > --
    > Mark Rae
    > ASP.NET MVP
    > http://www.markrae.net
    >
    >
     
    rodchar, Apr 9, 2008
    #3
  4. use
    DrpX.ClientID
    or sometimes
    DrpX.UniqueID

    depending on what you need name or id of the control...


    George.


    "rodchar" <> wrote in message
    news:...
    > yes Mark but this is the only way i know to get it thru javascript. is
    > there
    > another way?
    >
    > "Mark Rae [MVP]" wrote:
    >
    >> "rodchar" <> wrote in message
    >> news:...
    >>
    >> > what's the best way to extract info from the following string:
    >> >
    >> > controlvalueid_ctl02_DrpX
    >> >
    >> > i need "_Drp" and everything to the right of it.

    >>
    >> Are you trying to find the server-side control ID, as opposed to the
    >> "munged" client-side control ID...?
    >>
    >>
    >> --
    >> Mark Rae
    >> ASP.NET MVP
    >> http://www.markrae.net
    >>
    >>
     
    George Ter-Saakov, Apr 9, 2008
    #4
  5. rodchar

    rodchar Guest

    but that's on the server-side right? because i'm trying to get to the element
    in javascript.

    "George Ter-Saakov" wrote:

    > use
    > DrpX.ClientID
    > or sometimes
    > DrpX.UniqueID
    >
    > depending on what you need name or id of the control...
    >
    >
    > George.
    >
    >
    > "rodchar" <> wrote in message
    > news:...
    > > yes Mark but this is the only way i know to get it thru javascript. is
    > > there
    > > another way?
    > >
    > > "Mark Rae [MVP]" wrote:
    > >
    > >> "rodchar" <> wrote in message
    > >> news:...
    > >>
    > >> > what's the best way to extract info from the following string:
    > >> >
    > >> > controlvalueid_ctl02_DrpX
    > >> >
    > >> > i need "_Drp" and everything to the right of it.
    > >>
    > >> Are you trying to find the server-side control ID, as opposed to the
    > >> "munged" client-side control ID...?
    > >>
    > >>
    > >> --
    > >> Mark Rae
    > >> ASP.NET MVP
    > >> http://www.markrae.net
    > >>
    > >>

    >
    >
    >
     
    rodchar, Apr 9, 2008
    #5
  6. rodchar

    rodchar Guest

    can you use this if the textbox resides in a WebUserControl which in turn is
    on the .aspx page?

    i tried document.getElementById('<% WebUserControl1_TextBox1 %'>)
    but it won't compile, it says TextBox1 doesn't exist in this context.

    "Mark Rae [MVP]" wrote:

    > "rodchar" <> wrote in message
    > news:...
    >
    > [top-posting corrected]
    >
    > >> > what's the best way to extract info from the following string:
    > >> >
    > >> > controlvalueid_ctl02_DrpX
    > >> >
    > >> > i need "_Drp" and everything to the right of it.
    > >>
    > >> Are you trying to find the server-side control ID, as opposed to the
    > >> "munged" client-side control ID...?

    > >
    > > yes Mark but this is the only way i know to get it thru javascript. is
    > > there
    > > another way?

    >
    > You don't need it...
    >
    > If you have a server-side control called DrpX and want to refer to it in
    > client-side JavaScript, all you need is:
    >
    > <script type="text/javascript">
    > var DrpX = document.getElementById('<%=DrpX.ClientID%>');
    > </script>
    >
    >
    > --
    > Mark Rae
    > ASP.NET MVP
    > http://www.markrae.net
    >
    >
     
    rodchar, Apr 10, 2008
    #6
  7. rodchar

    rodchar Guest

    thanks for this one,
    rod.

    "bruce barker" wrote:

    >
    > var s = 'controlvalueid_ctl02_DrpX'.match(/_Drp.*$/)
    >
    > -- bruce (sqlwork.com)
    >
    >
    > "rodchar" wrote:
    >
    > > hey all,
    > > what's the best way to extract info from the following string:
    > >
    > > controlvalueid_ctl02_DrpX
    > >
    > > i need "_Drp" and everything to the right of it.
    > >
    > > thanks,
    > > rodchar
     
    rodchar, Apr 10, 2008
    #7
  8. rodchar

    rodchar Guest

    thanks Mark and everyone for this very helpful thread,
    rod.

    "Mark Rae [MVP]" wrote:

    > "rodchar" <> wrote in message
    > news:...
    >
    > [top-posting corrected again]
    >
    > >> >> > what's the best way to extract info from the following string:
    > >> >> >
    > >> >> > controlvalueid_ctl02_DrpX
    > >> >> >
    > >> >> > i need "_Drp" and everything to the right of it.
    > >> >>
    > >> >> Are you trying to find the server-side control ID, as opposed to the
    > >> >> "munged" client-side control ID...?
    > >> >
    > >> > yes Mark but this is the only way i know to get it thru javascript. is
    > >> > there
    > >> > another way?
    > >>
    > >> You don't need it...
    > >>
    > >> If you have a server-side control called DrpX and want to refer to it in
    > >> client-side JavaScript, all you need is:
    > >>
    > >> <script type="text/javascript">
    > >> var DrpX = document.getElementById('<%=DrpX.ClientID%>');
    > >> </script>

    > >
    > > can you use this if the textbox resides in a WebUserControl which in turn
    > > is
    > > on the .aspx page?

    >
    > Yes.
    >
    > > i tried document.getElementById('<% WebUserControl1_TextBox1 %'>)
    > > but it won't compile, it says TextBox1 doesn't exist in this context.

    >
    > Firstly, you need the = sign, which is ASP.NET shorthand for Response.Write
    >
    > Secondly, you need to specify the .ClientID property of the control whose
    > munged name you want to return...
    >
    >
    > --
    > Mark Rae
    > ASP.NET MVP
    > http://www.markrae.net
    >
    >
     
    rodchar, Apr 10, 2008
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Bob P.
    Replies:
    4
    Views:
    33,234
    Bob P.
    Oct 26, 2004
  2. Froggy_Jo

    File manipulation in JavaScript

    Froggy_Jo, Jul 24, 2003, in forum: Javascript
    Replies:
    0
    Views:
    131
    Froggy_Jo
    Jul 24, 2003
  3. Froggy_Jo

    File manipulation in JavaScript

    Froggy_Jo, Jul 24, 2003, in forum: Javascript
    Replies:
    1
    Views:
    127
    Grant Wagner
    Jul 25, 2003
  4. YT

    javascript string manipulation

    YT, Jul 31, 2003, in forum: Javascript
    Replies:
    1
    Views:
    95
    N Clements
    Aug 1, 2003
  5. Phrederik

    String manipulation in javascript?

    Phrederik, Sep 22, 2003, in forum: Javascript
    Replies:
    4
    Views:
    162
    Phrederik
    Sep 22, 2003
Loading...

Share This Page