Hi there,
I’m creating an online diary app using PHP MySQL and jQuery. Exciting times.
The problem I’ve run into is setting the state of a set of Radio buttons which determines how often an event recurs (if at all).
So I have three radio buttons like so:
<input type="radio" name="recur" id="never" value="X" checked>
<input type="radio" name="recur" id="weekly" value="W">
<input type="radio" name="recur" id="monthly" value="M">
This is fine for adding a new event, but I am also using the same form to edit an event. When it is in ‘edit mode’, the fields of the form are populated by an ajax call. This includes a hidden input .recurrence which is populated ‘X’, ‘W’, or ‘M’.
What I want to do is something like:
var recurrence = $('#events .selected .recurrence').val();
switch(recurrence){
case 'M': $('#monthly')[0].checked = true;
break;
case 'W': $('#weekly')[0].checked = true;
break;
default: $('#never')[0].checked = true;
break;
}
Which bizarrely will work when the event is monthly, but not when the event is weekly or never.
Also I can’t seem to reset the radio buttons, when I clear the form later in my script.
Any help greatly received,
Mike