I have this in my view
<script type='text/javascript'>
$(function(){
$('#users').click(function(){
alert($("tr[aria-selected=true] td:first").html())
})
})
</script>
And inside my users.js
$(function(){
$('#users').click(function(){
alert($("tr[aria-selected=true] td:first").html())
})
})
Having them,obviously not at the same time,gives me different results Basically I'm trying to retrieve the ID of the selected row finding it attr value.\
With the unobtrusive way right after loading the page I'd get "null" on my first click on a row and then every time I hit a row shows me the value that I clicked previously...TWICE!. But when keeping the script inside my view I get the result I want.
What am I doing wrong?
EDIT:
My view
<%=raw jqgrid("List of users", "users", "/users",
[
{ :field => "id", :label => "id",:width => 50 },
{ :field => "username", :label => "username",:width => 120,:editable => true },
{ :field => "email", :label => "email",:width => 120,:editable => true },
{ :field => "name", :label => "name",:width => 100,:editable => true },
{ :field => "lastname", :label => "lastname",:width => 100,:editable => true },
{ :field => "groups", :label => "roles",:width => 180}
] , {:add => true,:edit => true,:delete => true,:error_handler => "s",:inline_edit => 'true',:edit_url => post_data_users_url,:sortable_rows => 'true'}
) %>
<p><%= link_to "Edit roles",roles_path%>
<%= link_to "| Edit user",{:action => 'edit'},{:class => 'editLink hide'}%></p>
<script type='text/javascript'>
$(function(){
var _last = new String()
$('#users').click(function(){
_last = $("tr[aria-selected=true] td:first").html()
$(".editLink").attr("href","/users/edit/"+ _last)
$(".editLink").addClass('show')
})
})
</script>
My layout
<!DOCTYPE html>
<html>
<head>
<title>UserManager</title>
<%= stylesheet_link_tag "application", :media => "all" %>
<%= javascript_include_tag "application" %>
<%= csrf_meta_tags %>
<%=jqgrid_javascripts%>
<%=jqgrid_stylesheets%>
</head>
<body>
<div>
<%if flash[:notice]%>
<p><%= flash[:notice]%></p>
<%end%>
<%if current_user%>
Logged in as <%= current_user.username%> | <%= link_to 'logout', log_out_path%>
<%end%>
</div>
<%= yield %>
</body>
</html>
The way I see it...nothing special there