user123456789 user123456789 - 1 month ago 5
Javascript Question

ID.Replace not working

I have a gridview where when I click on the row I need to get the ID of that row.

So I created the click function which returns an ID like

gvBookingsRow_5


$(".gvBookingsRow_").click(function (e) {
ShowBookingComment($(this).attr("ID"));
});


So then in my function I need to separate the
gvBookingsRow_
from the
5
:

function ShowBookingComment(ID){
PageMethods.GetBookingComment(ID.replace("gvBookingsRow_",""),OnGetBookingComment,null);
}


I tried using
ID.replace
but it is still returning the ID
gvBookingsRow_5
. I just want it to return the number

Answer

Did you try assigning your ID with the replaced string like

Edit: Replace ID with id

$(".gvBookingsRow_").click(function (e) {
   ShowBookingComment($(this).attr("id"));                                                                
});

function ShowBookingComment(ID){
    ID = ID.replace("gvBookingsRow_","");
    PageMethods.GetBookingComment(ID, OnGetBookingComment,null);
} 
Comments