Francesca
Francesca

Reputation: 28148

Radio button onclick - change span content

Is it possible to do this with jQuery AJAX?

I'd like to change the content of a <span> when a radio button is selected.

<input class="unitSelectInches" type="radio" name="units" value="inches" />Inches
<input class="unitSelectCenti" type="radio" name="units" value="centi" />Centimetres

Selecting inches will change this span to say "inches" and centimetres too...

<span class="unitLabel">inches</span>

Upvotes: 0

Views: 739

Answers (2)

Paulo Lima
Paulo Lima

Reputation: 1238

did not you want it?

$("input[name=units]").on("change", function () {
   var selected = $("input[name=units]:checked");
   $(".unitLabel").text( selected.val());
 });

Upvotes: 1

Claudio Redi
Claudio Redi

Reputation: 68420

Probably you're confused, jQuery and Ajax are 2 different things. You just need jQuery for your requirement, ajax is not related at all.

Please try this

$('input[name="units"]').change(function() {
    $('.unitLabel').text(this.value);
})

DEMO

Upvotes: 1

Related Questions