获取所选单选按钮和隐藏值 [英] Get Selected radio button and hidden values

查看:91
本文介绍了获取所选单选按钮和隐藏值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有动态单选按钮.我必须获取所选单选按钮的值以及绑定到其的隐藏输入类型的值.我隐藏了一种输入类型,可以使用来传递选项ID

I have dynamic radio buttons. I've to get the value of selected radio button and value of hidden input type bound to it. I'm having one input type as hidden to pass option id using

<input type="radio" name="sareefinishing" value="<?php echo $opvalue->getTitle(); ?>" />
<input type="hidden" name="sareeOptionId" value="<?php echo $opvalue->getId(); ?>" />

以下是完整的代码:

  foreach ($productCollection->getOptions() as $value) {
        echo "Custom Option TITLE: <strong>" . $value->getTitle() . "</strong><br/>";

        $values = Mage::getSingleton('catalog/product_option_value')->getValuesCollection($value);
        foreach($values as $opvalue){
            ?>
            <?php  echo $opvalue->getTitle(); ?>

            <input type="radio" name="sareefinishing" value="<?php echo $opvalue->getTitle(); ?>" />
            <input type="hidden" name="sareeOptionId" value="<?php echo $opvalue->getId(); ?>" />

        <?php
        }

在我的Javascript文件中,我正在使用以下代码

In my Javascript file I'm using following code

var data = $j('#customoption').serializeArray(); //customoption is form id
alert(data);

我从<?php echo $opvalue->getTitle(); ?>的单选按钮值中获取了正确的选定标签,但不是<?php echo $opvalue->getTitle(); ?>的对应值id.它提供了所有id值.

I'm getting correct selected label from radio button value from <?php echo $opvalue->getTitle(); ?>but not it's corresponding value id from <?php echo $opvalue->getTitle(); ?>. It gives all id values.

推荐答案

这将是因为每个隐藏的输入都是表单的唯一元素,该表单的值不依赖于其他表单(列表不是这种情况)单选按钮.

It will because each hidden input is unique element for the form whose value is not dependent on others which is not the case with the list of radio buttons.

据我了解,您需要选中的单选按钮的相应隐藏值;您可以做的是

As far as I can understand, you need the selected radio button's corresponding hidden value; What you can do is

  1. 创建一个隐藏字段.
  2. 创建具有以下属性的单选按钮:data-sareeOptionId = <?php echo $opvalue->getId(); ?>
  3. 在单选按钮的更改上,使用on change事件使用javascript用单选按钮的data-sareeOptionId填充隐藏字段.
  4. 序列化表格.
  1. Create a single hidden field.
  2. Create the Radio button with attribute:data-sareeOptionId = <?php echo $opvalue->getId(); ?>
  3. On the change of radio button, fill the hidden field with the data-sareeOptionId of the radio button using javascript using on change event.
  4. Serialize the form.

代码流:Radio option喜欢

<input type="radio" data-sareeOptionId="<?php echo $opvalue->getId(); ?>" name="sareefinishing" value="<?php echo $opvalue->getTitle(); ?>" />

这篇关于获取所选单选按钮和隐藏值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆