Jump to content

JQuery get the value of checked input radio and display in span tag


nicola10

Recommended Posts

Hello

I would like to insert into a span tag the label of a radio button on checked status but It doesn't works and not showing errors

I'm trying the following code to test in the change function works property. Variables like name, id and value are recovered correctly but the content of tag span doesn't change

	    <script>
$(document).ready(function() {
  $('input[name="InputName" value="InputValue" id="InputID"]').change(function() {
    var value = $("input[name='InputName']:checked").val();
    $('#SpanID').text(value);
  });
	});
</script>
	

Any solution?

Link to comment
Share on other sites

Changing the controls and the event associated the id of the checked radio button is inserted into the content of span tag. But I do not know how to insert the option label and if I click another option, I have to double-click to update the content

	  $('label').click(function() {
    var value = $("input[name='InputName']:checked").val();
    $('#SpanID').text(value);
  });
	

Link to comment
Share on other sites

To get the label I changed

from

	var value = $("input[name='InputName']:checked").val();
	

to

	var value = $("input[name='InputName']:checked").next().text();
	

But when I change the selection I have to click 2 times to see the updated content into the span tag

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...