Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > javascript string manipulation

Reply
Thread Tools

javascript string manipulation

 
 
rodchar
Guest
Posts: n/a
 
      04-09-2008
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
 
Reply With Quote
 
 
 
 
bruce barker
Guest
Posts: n/a
 
      04-09-2008

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

 
Reply With Quote
 
 
 
 
rodchar
Guest
Posts: n/a
 
      04-09-2008
yes Mark but this is the only way i know to get it thru javascript. is there
another way?

"Mark Rae [MVP]" wrote:

> "rodchar" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>
> > 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
>
>

 
Reply With Quote
 
George Ter-Saakov
Guest
Posts: n/a
 
      04-09-2008
use
DrpX.ClientID
or sometimes
DrpX.UniqueID

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


George.


"rodchar" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> yes Mark but this is the only way i know to get it thru javascript. is
> there
> another way?
>
> "Mark Rae [MVP]" wrote:
>
>> "rodchar" <(E-Mail Removed)> wrote in message
>> news:(E-Mail Removed)...
>>
>> > 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
>>
>>



 
Reply With Quote
 
rodchar
Guest
Posts: n/a
 
      04-09-2008
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" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > yes Mark but this is the only way i know to get it thru javascript. is
> > there
> > another way?
> >
> > "Mark Rae [MVP]" wrote:
> >
> >> "rodchar" <(E-Mail Removed)> wrote in message
> >> news:(E-Mail Removed)...
> >>
> >> > 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
> >>
> >>

>
>
>

 
Reply With Quote
 
rodchar
Guest
Posts: n/a
 
      04-10-2008
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" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>
> [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
>
>

 
Reply With Quote
 
rodchar
Guest
Posts: n/a
 
      04-10-2008
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

 
Reply With Quote
 
rodchar
Guest
Posts: n/a
 
      04-10-2008
thanks Mark and everyone for this very helpful thread,
rod.

"Mark Rae [MVP]" wrote:

> "rodchar" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>
> [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
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Javascript listbox item manipulation, and codebehind Bob P. ASP .Net 4 10-26-2004 01:03 PM
String manipulation in javascript? Phrederik Javascript 4 09-22-2003 04:11 AM
javascript string manipulation YT Javascript 1 08-01-2003 02:22 AM
File manipulation in JavaScript Froggy_Jo Javascript 1 07-25-2003 03:05 PM
File manipulation in JavaScript Froggy_Jo Javascript 0 07-24-2003 08:55 PM



Advertisments