I am working on creating my own book that works like AJAX. It is based on a table with editable cells. The user clicks on the cell to enter a grade, and when they click on the cell, the class is sent to the database via AJAX. While it is working fine, except that I added that the user can press Enter and make him act as if the user had clicked somewhere else to close the editing form.
PROBLEM: when the user accesses return instead of input, the blur part works twice, as evidenced by the warning that appears twice. If they just click somewhere, that's fine. My understanding of jQuery.blur () is that if you call it without a callback or arguments, it acts as an executor and treats it as if the selected element lost focus.
It happens in IE8, Chrome and FF 4.0.1. The current version works on my test site
Can someone explain why it works twice when I try to set the blur on user login?
UPDATE: HTML code cannot be published because in fact the table and the set of table tags are not in the whiteOutflow list. (I'm new here, so there may be a way to do this, but I don't know that.)
In addition, I solved the immediate problem by changing
if(event.keyCode=='13') { $('#gradeUpdate').blur(); }
to
if(event.keyCode=='13') { $("#gradeUpdate").parent().focus(); //$('#gradeUpdate').blur(); }
but I still would like to know why the original line doesn't just make #gradeUpdate blur as I thought.
Everything happens inside this function:
function clickableCell(){ $("td.assignmentCell").click(function(){ //if a td with an assignment class is clicked, if( clicked == 0) { clicked = 1; currentValue = $(this).text();//get the current value of the entered grade var passable = this; alert("Test: passable is: "+$(passable).text()); //change content to be an editable input form element $(this).html("<input name='gradeUpdate' id='gradeUpdate' size=3 value='"+currentValue+"' type='text' />"); //move the cursor to the new input and highlight the value for easy deletion $('#gradeUpdate').focus().select(); //watch for keystrokes somewhere else and act appropriately $(document).keyup(function(event){ //if they hit Enter, treat it like they clicked somewhere else if(event.keyCode=='13') { $('#gradeUpdate').blur(); } }); $('#gradeUpdate').blur(function(passable){ //reset the clicked counter clicked = 0; //check to see if the value is blank or hasn't changed var inputValue = $('
and here is the full HTML of the source page; it's really just a table with some pre-entered values that you need to use for testing. My next step is to build the table on the fly with the XML returned from the AJAX request.