Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,
I want to get textbox id and value of that textbox inside Gridview on keyup event using jquery.I used $("[id*=gridId] [id*=txtboxId]").keyup(function(){} this code to get but its only returing single textbox's (txtboxId) id and value.I have asp.net textbox control.I want to get unique id generated in each textbox inside gridview.


Thanks in Advance ;-)

What I have tried:

I used $("[id*=gridId] [id*=txtboxId]").keyup(function(){} this code to get but its only returing single textbox's (txtboxId) id and value
Posted
Updated 3-May-16 20:12pm
v2
Comments
Karthik_Mahalingam 4-May-16 1:57am    
yes it will return only the current textbox object only.
what is your exact issue ?

You can set a common class for your textbox inside grid and then using class you can get text box id and it's value.

here i have just given an example. it's not in grid but it should work for gridview too.

HTML
<input type="text" id="txtB1" class="commanClass" />
<input type="text" id="txtB2" class="commanClass" />
<input type="text" id="txtB3" class="commanClass" />
<input type="text" id="txtB4" class="commanClass" />


JavaScript
$(document).ready(function()
{
   $('.commanClass').keyup(function(){
   var $eleId = $(this).attr("id");
    var currentVal = $(this).val();
    alert($eleId);
    alert(currentVal);
   });
});
 
Share this answer
 
Comments
Maniraj.M 4-May-16 1:56am    
I have asp.net textbox control.I want to get unique id generated in each textbox inside gridview
Raje_ 4-May-16 1:59am    
So what is the issue? You will get the id after running this code. Do you want to get all text box ids at same time when you fire keyup event on any text box?
if so then use this :
$(document).ready(function() {
$('.commanClass').keyup(function() {
$('.commanClass').each(function() {
var $id = $(this).attr("id");
var value = $(this).val();
alert($id);
alert(value);
});
});
});
Maniraj.M 4-May-16 2:03am    
i dont want all id's of textbox. Where the keyup event fires i need that particular textbox id its enough.But textboxes in gridview
Raje_ 4-May-16 2:06am    
even if it is in gridview it will work. did you try first code i have given. make sure you add common class for textbox.
try this

JavaScript
$(function () {

          $("input[type='text']", $('#' + '<%= gridId.ClientID%>')).keyup(function (e) {

              var id = $(this).attr('id');
              var value = $(this).val();
              alert(id  + ' = ' + value)
          });

      });
 
Share this answer
 
Comments
Maniraj.M 4-May-16 3:02am    
i used $("input[type='text'][id*=txtid]").keyup(function(){
});
it worked..
Thanks u ;-)
Karthik_Mahalingam 4-May-16 3:09am    
welcome :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900