Split radio button values using jquery / Javascript -
i want split radio button values form know option chosen is, price. value before | separator price , value after | option chosen.
<input type="radio" name="arm" value="50|1" id="split" required> option: 1<br> <input type="radio" name="arm" value="100|2" id="split" required> option: 2<br> <input type="radio" name="arm" value="150|3" id="split" required> option: 3<br> <input type="radio" name="mechanism" value="50|1"> option: 1<br> <input type="radio" name="mechanism" value="100|2"> option: 2<br> <input type="radio" name="mechanism" value="150|3"> option: 3<br> <input type="radio" name="base" value="50|1"> option: 1<br> <input type="radio" name="base" value="100|2"> option: 2<br> <input type="radio" name="fabric" value="50|1"> option: 1<br> <input type="radio" name="fabric" value="50|2"> option: 2<br> <input type="radio" name="fabric" value="50|3"> option: 3<br> <script> jquery(":text[name='quantity'], :radio[name='arm'], :radio[name='mechanism'], :radio[name='base'], :radio[name='fabric']").change(function(){ var arm = jquery(":radio[name='arm']:checked"); var arr = arm.split('|'); var $mechanism = jquery(":radio[name='mechanism']:checked"); var $base = jquery(":radio[name='base']:checked"); var $fabric = jquery(":radio[name='fabric']:checked"); var $quantity = jquery(":text[name='quantity']"); if($arm.length ==1){ var = parseint($arm.val(arr[0]), 10); var m = parseint($mechanism.val(), 10); var b = parseint($base.val(), 10); var f = parseint($fabric.val(), 10); var q = parseint($quantity.val(), 10); jquery("#result").val((a + m + b + f) * q); } }); </script>
i trying split values using:
var arm = jquery(":radio[name='arm']:checked"); var arr = arm.split('|');
and passing value follows:
var = parseint($arm.val(arr[0]), 10);
this not work. no jquery or javascript guru, should make work?
this line:
var arr = arm.split('|');
you need value
of arm
, split that.
var arr = arm.val().split('|');
Comments
Post a Comment