tags:

views:

241

answers:

2

I am creating an AJAX application. When a user selects a button a new input element is added to the web page and filled with data. After the new input box is added (id = 'Input_thingy') to the web page I would like to select the text. The problem I am having is that the text in the new input box is selected for only a brief moment. This is all occurring during context of the execution of JQuery's "ajax" command:

$.ajax({
 type: "POST",
 url: "DoSomething.php",
 data: info,
 success: function(data) 
  {
  $('#Input_thingy').select();
         return false;
  },
 });

I suspect that the problem has to do with the fact that the selection command occurs in the ajax command area, but I am at a loss as to how do this correctly. Any help?

+1  A: 

Not sure, but perhaps the new input is losing focus when you return false. Have you considered putting the select statement on a timer like so:

setTimeout(function() { $('#Input_thingy').select(); }, 100);

This will wait until 100 milliseconds after the success to fire the text selection.

Topher Fangio
Works like a charm. Thanks.
jay
A: 

You might want to try using just the $.post() function

$.post("DoSomething.php",
        { SomeDataToPost: "put data here"},
        function(data){
            $('#Input_thingy').focus().select();
       });
RhinoDevX64
I am using the full functionality of the ajax command. I just showed the part with the problem.
jay