0

hi i am trying to create a form where user selects either am or pm sessions for each day of the week except Monday where only am is available.

my code is currently:

    <table border="0" id="EnrollPreSes">        
    <tr>
        <td>Day</td>
        <td>AM <br/> 8:30 - 11:30 </td>
        <td>PM <br/> 12:00 - 3:00</td>
    </tr>
    <tr>
        <td>Monday</td>
        <td><input type="checkbox" name="Prefses[]" id="mam" value="MonAM"></td>
        <td></td>
    </tr>
    <tr>
        <td>Tuesday</td>
        <td>
                 <input type="radio" name="Prefses" value="TueAM">  
        </td>
        <td>
            <input type="radio" name="Prefses" value="TuePM">
        </td>
    </tr>
    <tr>
        <td>Wednesday</td>
        <td>
            <input type="radio" name="Prefses" value="WedAM">
        </td>
        <td>
            <input type="radio" name="Prefses" value="WedPM">
        </td>
    </tr>
</table>

and so on for the rest of the week, is there a way to allow only an am or pm slot for each day to be selected and then be sent to my php script as an array?

Mattyboi1670
  • 37
  • 10
  • 4
    Why not just use a radio button for the AM/PM selection? – StuR Jan 24 '13 at 13:21
  • would that work tho as they can have for instance monday am tuesday pm wednesday Pm thursday am friday am ? – Mattyboi1670 Jan 24 '13 at 13:23
  • yes each row would have their own linked check boxes just means you'll have to request 7 days worth of post vars (only 7 as 2 checkboxes respond as one when linked) – Dave Jan 24 '13 at 13:25

3 Answers3

0

It'd be easier to have one Am radio and one Pm radio, but if you really want it:

$(document).ready(function () {
    $('input > radio').click(function () {
        $(this).siblings().removeAttr('checked');
    )}
)}

I know you've a checkbox for monday so it could be adapted to accommodate both.

Niall Paterson
  • 3,580
  • 3
  • 29
  • 37
0

A pointed out in this answer using jquery you can add class unique to your checkbox and then:

var $unique = $('input.unique');
$unique.click(function() {
$unique.filter(':checked').not(this).removeAttr('checked');

});

Community
  • 1
  • 1
v0d1ch
  • 2,738
  • 1
  • 22
  • 27
  • between he script tags in the head of your document and don't forget to add class="unique" to your checkbox and include jquery at the top of the page – v0d1ch Jan 24 '13 at 13:45
0

Give each rows radio buttons the same name, jsFiddle here:

http://jsfiddle.net/QTCy2/8/

<form id="EnrollPreSes">
<table border="0" id="EnrollPreSes">        
    <tr>
        <td>Day</td>
        <td>AM <br/> 8:30 - 11:30 </td>
        <td>PM <br/> 12:00 - 3:00</td>
    </tr>
    <tr>
        <td>Monday</td>
        <td>
        <input type="radio" name="monday" value="MonAM">  
        </td>
        <td>
            <input type="radio" name="monday" value="MonPM">
        </td>
    </tr>
    <tr>
        <td>Tuesday</td>
        <td>
                 <input type="radio" name="tuesday" value="TueAM">  
        </td>
        <td>
            <input type="radio" name="tuesday" value="TuePM">
        </td>
    </tr>
    <tr>
        <td>Wednesday</td>
        <td>
            <input type="radio" name="wednesday" value="WedAM">
        </td>
        <td>
            <input type="radio" name="wednesday" value="WedPM">
        </td>
    </tr>
</table>

       <input type="submit" value="Submit">

</form>

$(function(){
    $('#EnrollPreSes').on('submit', function() {
       alert($(this).serialize()); //Send to your PHP script
        return false; 
    });
});
StuR
  • 12,042
  • 9
  • 45
  • 66