Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Select Text on click Using jQuery

I want to fix the following issue in Firefox

When i try to select the text inside the textbox using double click on mouse its not selecting the text the cursor goes to the start of the text.Any ideas how to fix this?but this works fine in googlechrome

i tried the following from this http://www.iwebux.com/demos/ajax/ i this link when you try to edit the price column you cant select the value.Thank you.

my code:

 $(document).ready(function () {
     $('td.edit').click(function () {
         $('.ajax').html($('.ajax input').val());
         $('.ajax').removeClass('ajax');

         $(this).addClass('ajax');
         $(this).html('<input id="editbox"  size="' + $(this).text().length + '" type="text" value="' + $(this).text() + '">');

         $('#editbox ').focus();
     });

     $('td.edit').keydown(function (event) {
         arr = $(this).attr('class').split(" ");
         if (event.which == 13) {
             $.ajax({
                 type: "POST",
                 url: "supplierprice/config.php",
                 data: "value=" + $('.ajax input').val() + "&rowid=" + arr[2] + "&field=" + arr[1],
                 success: function (data) {
                     $('.ajax').html($('.ajax input').val());
                     $('.ajax').removeClass('ajax');
                 }
             });
         }
     });

     $('#editbox').live('blur', function () {
         $('.ajax').html($('.ajax input').val());
         $('.ajax').removeClass('ajax');
     });
 });
like image 644
Xavi Avatar asked Sep 24 '26 22:09

Xavi


1 Answers

Try using .select() function. This is used to select the text in the editable input elements.

In your case, try adding the line

$('#editbox').select();

below the line

$('#editbox ').focus();

Hope this hepls.

like image 136
bubi Avatar answered Sep 26 '26 12:09

bubi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!