Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can solve this by wrapping the code in your tr's click event with an if statement that checks which element was actually clicked. This will cause your code to only hide/show the inputs when the user clicks directly on a <code>&lt;td&gt;</code> or <code>&lt;span&gt;</code> with the appropriate class. That will allow you to get rid of the '.editbox' mouseup event handler.</p> <p><a href="http://jsfiddle.net/craigm/gKaUy/" rel="nofollow">jsFiddle</a> (The first row in the fiddle displays a select box instead of just two inputs so you can see that this code works. The ajax call is also commented in the fiddle.)</p> <pre><code>$(document).ready(function() { $(".edit_tr").click(function(e) { if ($(e.target).hasClass('edit_td') || $(e.target).hasClass('text')) { var ID = $(this).attr('id'); $("#first_" + ID).hide(); $("#last_" + ID).hide(); $("#first_input_" + ID).show(); $("#last_input_" + ID).show(); } }).change(function() { var ID = $(this).attr('id'); var first = $("#first_input_" + ID).val(); var last = $("#last_input_" + ID).val(); var dataString = 'id=' + ID + '&amp;firstname=' + first + '&amp;lastname=' + last; $("#first_" + ID).html('&lt;img src="load.gif" /&gt;'); // Loading image if (first.length &gt; 0 &amp;&amp; last.length &gt; 0) { $.ajax({ type: "POST", url: "table_edit_ajax.php", data: dataString, cache: false, success: function(html) { $("#first_" + ID).html(first); $("#last_" + ID).html(last); } }); } else { alert('Enter something.'); } }); // Outside click action $(document).mouseup(function(e) { if (!$(e.target).hasClass('editbox')) { $(".editbox").hide(); $(".text").show(); } }); }); </code></pre> <p>The relevant code above is: </p> <pre><code>$(".edit_tr").click(function(e) { if ($(e.target).hasClass('edit_td') || $(e.target).hasClass('text')) { var ID = $(this).attr('id'); $("#first_" + ID).hide(); $("#last_" + ID).hide(); $("#first_input_" + ID).show(); $("#last_input_" + ID).show(); } }) </code></pre> <p>Don't forget to remove this code:</p> <pre><code>$(".editbox").mouseup(function() { return false }); </code></pre> <p><strong>Edit:</strong> You'll need to do something similar in the 'document' click handler. Except here, you're ignoring the clicks if the target has the 'editbox' class.</p> <pre><code>// Outside click action $(document).mouseup(function(e) { if (!$(e.target).hasClass('editbox')) { $(".editbox").hide(); $(".text").show(); } }); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload