javascript string manipulation

  • Thread starter Thread starter rodchar
  • Start date Start date
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
 
yes Mark but this is the only way i know to get it thru javascript. is there
another way?
 
use
DrpX.ClientID
or sometimes
DrpX.UniqueID

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


George.
 
but that's on the server-side right? because i'm trying to get to the element
in javascript.
 
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>
 
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...
 
Back
Top