javascript string manipulation

R

rodchar

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
 
B

bruce barker

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

-- bruce (sqlwork.com)
 
R

rodchar

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

George Ter-Saakov

use
DrpX.ClientID
or sometimes
DrpX.UniqueID

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


George.
 
R

rodchar

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

rodchar

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 said:
[top-posting corrected]
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>
 
R

rodchar

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

Mark Rae said:
[top-posting corrected again]
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...
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top