0

I have this fiddle: https://jsfiddle.net/wbtodgks/2/

jQuery(function($) {
    $(".parcelshop").click(function() {
        $("#address_lastname").val(this.value); // Put the value into the Amount field
    });
});

<input type="radio" class="parcelshop" name="data[shipping_address][address_firstname]" value="95621"> Click me

<input type="text" value="D1" id="address_lastname" name="data[shipping_address][address_lastname]">

And while it works in this controlled setup, I can't get it to work on my site.

I'm getting values from AJAX that populate a DIV - in this DIV I have a radio button for each result. I'm looking for a way to send the value of the user selected radio button to a input field, and I just can't get it to work.

Is it because the way AJAX works, that my javascript doesn't "see" the content of my AJAX output in the DIV?

Any pointers or help would be greatly appreciated. Thanks

Dyvel
  • 847
  • 1
  • 8
  • 20
  • You need to use a delegated event handler as the `radio` inputs you attach the event to are appended via an AJAX request after the DOM is loaded. See the question I marked as duplicate for more information – Rory McCrossan Jun 21 '16 at 10:57
  • Thanks - I've tried to modify my code using this method, but can't seem to make it work. What I've tried now is this: https://jsfiddle.net/wbtodgks/4/ Can you see any obvious wrong? – Dyvel Jun 21 '16 at 11:27
  • Got it working now... thanks for your help. You pointed me in the right direction. Please leave an answer :-) – Dyvel Jun 21 '16 at 11:59

0 Answers0