SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Addict
    Join Date
    Oct 2009
    Location
    London, UK
    Posts
    382
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Question Radio Buttons with jQuery

    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:
    Code:
    <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:
    Code:
    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

  2. #2
    SitePoint Addict
    Join Date
    Oct 2009
    Location
    London, UK
    Posts
    382
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Please be aware, this actually works fine. Dunno what happened on that day, but the code above works fine now.


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •