简体   繁体   English

使用jquery或javascript将单选按钮值组合为隐藏的表单元素

[英]Combining Radio button values into a hidden form element using jquery or javascript

I have form where people search for a profile match on two values. 我有一个表格,人们在其中搜索一个配置文件以匹配两个值。 In this case their role Specialist, Doctor or Nurse and their ranking - Gold, Silver or Bronze. 在这种情况下,他们的角色是专家,医生或护士,以及他们的排名-金,银或铜牌。

I need to be able to join these values and send to a hidden input which is submitted with the form. 我需要能够加入这些值并将其发送到与表单一起提交的隐藏输入中。 For example <input name="Icon" type="hidden" value="NurseSilver" /> is then used to determine which icon can be represented on a map that's returned. 例如,然后使用<input name="Icon" type="hidden" value="NurseSilver" />来确定可以在返回的地图上表示的图标。 My code is looking something like this... 我的代码看起来像这样...

<input type="radio" name="role" value="Specialist" id="role1" />
<input type="radio" name="role" value="Doctor" id="role2" />
<input type="radio" name="role" value="Nurse" id="role3" />

<input type="radio" name="rank" value="Gold" id="rank1" />
<input type="radio" name="rank" value="Silver" id="rank2" />
<input type="radio" name="rank" value="Bronze" id="rank3" />

<input name="Icon" type="hidden" value="" />

Thanks for looking... 感谢您的关注...

$('input[type=radio]').change(function(){
   $('input[name=Icon]').val(
      $('input[name=role]:checked').val()+
      $('input[name=rank]:checked').val()
   );
});

You can do something like this: 您可以执行以下操作:

var selRole = $(":radio[name=role] :checked").val();
var selRank = $(":radio[name=rank] :checked").val();
$(":hidden[name=Icon]").val(selRole + selRank);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM