0

Check this fiddle

http://jsfiddle.net/8FXFE/6/

This code does show the message when a radio button from name="txtNumber" is changed..

Now what i m trying to achieve is making a formula based on the values of name="txtSpace" & name="txtNumber" radio buttons..

My target is that suppose some one clicks on a radio button in txtNumber fields and another option in txtSpace fields there shall be some calculation of those in "output" window. Calculation can be addition of values of selected radio in txtNumber fields txtSpace fields..

but i m stuck in code and not know how can i change it??

Junk code

<div class="textForm">
<input type="radio" name="txtNumber" value="100" checked="checked" />100
<input type="radio" name="txtNumber" value="200" />200
<input type="radio" name="txtNumber" value="500" />500
<input type="radio" name="txtNumber" value="1000" />1000
<input type="radio" name="txtNumber" value="10000" />10000
<input type="radio" name="txtNumber" value="other" />other
<input type="text" name="other_field" id="other_field" onblur="checktext(this);"
/>
</div>
1
  • what do you want on the output part. can you put any example or something like that Commented Jan 31, 2013 at 10:57

3 Answers 3

1

If I got your question right you want to display an output determined by both checked radio inputs.

$(document).ready(function () {
    console.log("parsed");
    $("input[name='txtNumber'],input[name='txtSpace']").change(function () {
        $("#output").text("Changed to "+$("input[name='txtNumber']:checked").val() + " " +$("input[name='txtSpace']:checked").val()); 
    });
});

http://jsfiddle.net/8FXFE/8/

Sign up to request clarification or add additional context in comments.

Comments

0

used change() function and :checked.val() to get the value of checked radio button.. and added the value in txtNumber and txtSpace

try this

$(document).ready(function () {
  $("input[name='txtNumber'],input[name='txtSpace']").change(function () {
    var totalsum=parseInt($("input[name='txtNumber']:checked").val()) + parseInt($("input[name='txtSpace']:checked").val());
    $("#output").text("Changed to " + totalsum);

  });
});

fiddle here

Comments

0

I think you just need to build your string?

http://jsfiddle.net/8FXFE/7/

$("#output").text("Changed to " + $("input[name='txtNumber']:checked").val());

or if you want to combine both outputs you could try something like...

http://jsfiddle.net/8FXFE/10/

$("#output")[0].innerHTML ="Changed to " + $(this).val() + "<br/>" + 
  $('input[name="txtSpace"]:checked').val() + ' ' +
    $('input[name="txtNumber"]:checked').val();

..although you don't say what calculation should take place as 'Space 1 * 1000' doesn't make sense and neither would 'RJ * 200' etc... So I have just combined both radio selections.

1 Comment

$("input[name='txtNumber']:checked") could be $(this)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.