0

I have more than 2 Radio buttons and want to populate the value of "showtype_cost" when a radio button is checked. and change the value when another is checked

<body>
   <input name="showtype" type="radio" id="basic" value="basic" />Basic Slideshow<br />

   <input name="showtype" type="radio" id="lovestory" value="lovestory" /> Love Story <br />

   <input name="showtype_cost" type="text" id="text" value="">
   <p></p>
</body>
5
  • What do you mean by 'realise value'?
    – asprin
    Oct 22, 2012 at 7:38
  • 2
    using the same name for more than one element is not a good practice. Oct 22, 2012 at 7:48
  • @asprin I think he meant release the value, but after a radio button is checked, only another can be checked, it cannot be unchecked Oct 22, 2012 at 8:30
  • @WebnetMobile.com For radio buttons, isn't it necessary to use the same name so that only one radio button can be selected at a time?
    – asprin
    Oct 23, 2012 at 5:43
  • @aspirin: you're right. I overlooked the fact it's radio group. Oct 23, 2012 at 7:23

3 Answers 3

0

You can use this method, it may help you.

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#basic").click(function(){
$("#text").attr("value","150");
});
});
$(document).ready(function(){
$("#lovestory").click(function(){
$("#text").attr("value","500");
});
});
</script>
</head>
<body>
<input name="showtype" type="radio" id="basic" value="basic" />Basic Slideshow<br />

<input name="showtype" type="radio" id="lovestory" value="lovestory" /> Love Story <br />

<input name="showtype_cost" type="text" id="text" value="100">
<p></p>
</body>
</html>
0
0
$('input:radio[name="showtype"]').change(function(){
    $('input:text[name="showtype_cost"]').val($('input:radio[name="showtype"]:checked').val());
});
0
-2
$(document).ready(function(){ 
   $('*[name=showtype]').click(function(){
        $("#text").val($(this).val());
        });
    });
});

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.