2

So I thought I had this script working till I ran into the issue with Ajax. I have the script so if the user clicks on the item it will automatically change the value on the item. It was looking until I tried to refresh the listview after the change. It looks like Ajax would be the best bet. However the click event I was using has a issue when Ajax is ran. I looked online and it looks like I need to use the .on instead of the .click. I have tried all different ways but I cant get it to work. The code is below,

<script src="https://code.jquery.com/jquery-1.11.2.min.js" type="text/javascript"></script><script type="text/javascript">
$(document).ready(function() {
$(".ms-listviewtable > tbody > tr").click(function(){  //only works before ajax runs
    setTimeout( function() {
    //alert("Hello! I am an alert box!!");
    var ctx = SP.ClientContext.get_current("https://...");
    var items = SP.ListOperation.Selection.getSelectedItems(ctx);
    var clientContext = new SP.ClientContext();
    var oList = clientContext.get_web().get_lists().getByTitle('Ticket');
    this.oListItem = oList.getItemById(items[0].id);
    this.oListItem.set_item('read','yes');
    this.oListItem.update(); 
    clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
    }, 200);  //had to be put in place to give time for the list to be selected
}); 
}); 

So how can I convert this line to use the .on, $(".ms-listviewtable > tbody > tr").click(function(){

or another way to do a click event on the listview. Meaning if they click in item on the list and it run this code.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.