Why don't you check your old thread for responses instead of posting
the same thing twice?

http://groups.google.com/group/jquery-en/browse_thread/thread/c94d4da1f304e2d/0b7b2b0e9c9ea11e?hl=en&lnk=gst&q=ajax#0b7b2b0e9c9ea11e

Do what I said there, and also make sure that your PHP script is
working correctly. You need to add the events after the button has
been inserted into the page. (or use .live(), in jquery 1.3, but 1st
option might be easier at first)
Just load up your test-ajax.php in the browser with params, and see if
it outputs the html it should.

And where exactly in the code did you execute var
x=document.getElementsByName("test_select_1");? If it's not inside the
'success' function, it probably won't work.




On Jan 16, 1:53 pm, Mikael <mhedeng...@gmail.com> wrote:
> Hi all,
>
> I want to make a selection in a list created by a php-file that is
> called from another php-file using jQuery and ajax but I can not get
> any events to the newly created html elements.
>
> My example is very limited but shows the main problem.
>
> The first php-file has abutton defined like this:
>   <input class="mini_browse" name="mini_browse_btn"
> id="mini_browse_btn" type="button" value="Browse test" />
>
> I also have a div to show the result:
>   <div id="myresult">Show the result here</div>
>
> The jQuery entry looks like this:
> jQuery(document).ready(function($) {
>         $('.mini_browse').bind("click", function() {
>                 $.ajax({
>                         type: "get", url: "test-ajax.php", data: { action: 
> 'test' },
>                         error: function() {$("#myresult").html("Ajax 
> error");},
>                         success: function(html){ //so, if data is retrieved, 
> store it in
> html
>                                 $("#myresult").html(html);
>                         }
>                 }); //close jQuery.ajax
>                 return false;
>         });
>
> });
>
> When I click the button I get a call to test-ajax.php as expected and
> the output is displayed in the myresult div.
>
> The test-ajax.php executes this:
>   echo '<input class="test_select" type="button" name="test_select_1"
> id="test_select_1" value="Select" />';
>
> Firebug console reports this response:
>   <input class="test_select" type="button" name="test_select_1"
> id="test_select_1" value="Select" />
>
> The updated div shows this result (according to Firebug):
>   <div id="myresult">
>     <input id="test_select_1" class="test_select" type="button"
> value="Select" name="test_select_1"/>
>   </div>
>
> I can not get any events from the newly created button and when I
> execute
>   var x=document.getElementsByName("test_select_1");
> x.length returns zero so the element seems not to exist.
>
> Do I have to do anything to get the newly created element into the
> documents DOM or what can I do to make this work?
>
> Thanks!

Reply via email to