1
votes

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(); ?>" />

Here is complete code:

  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
        }

In my Javascript file I'm using following code

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

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.

enter image description here

2
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 - Tushar
@TusharGupta: How I can get hidden value corresponding to the selected radio button? - amitshree
google it use jquery or js your wish - CY5

2 Answers

1
votes

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. 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.

Code Flow : Radio option Like

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

Because you have sareeOptionId all as the same name

Make them a different name and it won't combine them into one value