Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JQUERY: Finding by control ID

Tags:

jquery

asp.net

Currently my aspx page contains

<input type="text" name="openid_username" />
<input type="text" name="openid_identifier" />

but now i would like to replace them with

<asp:TextBox ID="openid_username" runat="server"></asp:TextBox>
<asp:TextBox ID="openid_identifier" runat="server"></asp:TextBox>

so how should i modify the following JQUERY, to reflect the input boxes to textboxes replacement?

  var $usr = $this.find('input[name=openid_username]');
  var $id = $this.find('input[name=openid_identifier]');
like image 912
OrElse Avatar asked Mar 20 '11 19:03

OrElse


3 Answers

I would use the "ends with" option on the attribute selector in case the name is mangled by the control being in a container. Note the $= instead of =.

var $usr = $this.find('input[name$=openid_username]');
var $id = $this.find('input[name$=openid_identifier]');
like image 83
tvanfosson Avatar answered Nov 01 '22 23:11

tvanfosson


If you want the exact ID of your controls, you can do this:

var $usr = $this.find('#<%= openid_username.ClientID %>');
var $id = $this.find('#<%= openid_identifier.ClientID %>');

Of course, this is assuming your JS isn't in an external file.

like image 38
Cᴏʀʏ Avatar answered Nov 01 '22 23:11

Cᴏʀʏ


 var $usr=$("#openid_username");

should work or try

 var $usr = $('[id*=openid_username]');
like image 2
Hogan Avatar answered Nov 01 '22 22:11

Hogan