Search code examples
jqueryradiobuttonlist

JQUERY buttonset radio multiple on one page


Hey all I'm trying to get multiple radio buttons to work on one page. This is the idea I have.

I have several selections

        Days 1 2 3 4 5
Item         x
Item 2         x
Item 3               x

I would like to recite this idea with jquery. I have the basic layout in html and i have the appriate radio buttons in place ready for selection, workds a charm, but adding the jquery buttonset doesn't work for me as a class, as an ID obviously it will change each item.

THE JAVASCRIPT

$( ".radio-days" ).buttonset();

THE PEE HAYCH PEE

<?php 
    for($j = 0; $j < 5; $j++)
    {
?>

    <form>
        <div id='item<?php echo $j; ?>' class='radio-days'>
        <?php 
            for($i = 0; $i < 8; $i++)
            {
            ?>
            <input type="radio" id="radio<?php echo $i; ?>" name="radio<?php echo $i; ?>" /><label for="radio<?php echo $i; ?>"><?php echo $i; ?></label>
            <?php
            }
        ?>
        </div>
    </form>

<?php
    }
?>

in absolute dire need of help here :(


Solution

  • You cannot assign an id with multiple elements in html. Try

    <?php 
        for($j = 0; $j < 5; $j++)
        {
    ?>
    
        <form>
            <div id='item<?php echo $j; ?>' class='radio-days'>
            <?php 
                for($i = 0; $i < 8; $i++)
                {
                ?>
                <input type="radio" id="radio<?php echo $j; ?>_<?php echo $i; ?>" name="radio<?php echo $j; ?>" /><label for="radio<?php echo $j; ?>_<?php echo $i; ?>"><?php echo $i; ?></label>
                <?php
                }
            ?>
            </div>
        </form>
    
    <?php
        }
    ?>