mercredi 8 mars 2017

Store dropdown value and apply to checkbox when clicked

I am trying to change the 'value' of the checkbox when an item is selected from a dropdown list and then the checkbox is clicked. I have got a jquery function storing the value from the dropbox (I havent included the code from the dropdown list because it works fine and is not an issue. studentclass is the element from the dropdown list obviously):

<script src="http://ift.tt/1oMJErh"></script>
    <script>
        $(document).on('click', '.studentclass', function() {
            var clickeditem = $(this).text();

        });

    </script>

I then have my Checkbox code:

<div id="floorplan">
        <form name="assignrooms" class="myForm" action="assignrooms.php" method="post">
    <table id="roomselect">
        <tr>
        <td id="asg"><input type="checkbox" value="muffin" name="theroom" id="room1" class="room"/><label id="roomlabel" for="room1">Room 1</label></td>
        <td id="asg"><input type="checkbox" value="goodbye" name="theroom" id="room2" class="room"/><label id="roomlabel" for="room2">Room 2</label></td>
        <td id="asg"><input type="checkbox" name="theroom" id="room3" class="room"/><label id="roomlabel" for="room3">Room 3</label></td>
        <td id="asg"><input type="checkbox" name="theroom" id="room4" class="room"/><label id="roomlabel" for="room4">Room 4</label></td>
        <td id="asg"><input type="checkbox" name="theroom" id="room5" class="room"/><label id="roomlabel" for="room5">Room 5</label></td>
        <td id="asg"><input type="checkbox" name="theroom" id="room6" class="room"/><label id="roomlabel" for="room6">Room 6</label></td>
            </tr>
        <tr>
        <td id="asg"><input type="checkbox" name="theroom" id="room7" class="room"/><label id="roomlabel" for="room7">Room 7</label></td>
        <td id="asg"><input type="checkbox" name="theroom" id="room8" class="room"/><label id="roomlabel" for="room8">Room 8</label></td>
        <td id="asg"><input type="checkbox" name="theroom" id="room9" class="room"/><label id="roomlabel" for="room9">Room 9</label></td>
        <td id="asg"><input type="checkbox" name="theroom" id="room10" class="room"/><label id="roomlabel" for="room10">Room 10</label></td>
        <td id="asg"><input type="checkbox" name="theroom" id="room11" class="room"/><label id="roomlabel" for="room11">Room 11</label></td>
        <td id="asg"><input type="checkbox" name="theroom" id="room12" class="room"/><label id="roomlabel" for="room12">Room 12</label></td>
            </tr>
    </table>
            <input id="assignconfirm" name="submitroom" type="submit" value="Assign">
            </form>
        </div>

Ive looked around and cant find how to apply the 'clickeditem' variable to the 'value' of the checkbox when a checkbox is clicked.




Aucun commentaire:

Enregistrer un commentaire