jQuery way to handle select lists, radio buttons and checkboxes
        Posted  
        
            by Álvaro G. Vicario
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Álvaro G. Vicario
        
        
        
        Published on 2010-05-20T15:23:47Z
        Indexed on 
            2010/05/20
            15:30 UTC
        
        
        Read the original article
        Hit count: 258
        
When I handle HTML form elements with jQuery, I always end up with an ugly mix of jQuery syntax and plain JavaScript like, e.g.:
function doStuff($combo){
    if( $combo.get(0).options[$combo.get(0).selectedIndex].value=="" ){
        var txt = "";
    }else{
        var txt = $combo.get(0).options[$combo.get(0).selectedIndex].text;
    }
    var $description = $combo.closest("div.item").find("input[name$=\[description\]]");
    $description.val(txt);
}
Are there standard jQuery methods to handle typical operations on elements like <select>, <input type="radio"> and <input type="checkbox">?
With typical, I mean stuff like reading the value of the selected radio button in a group or replacing elements in a selection list. I haven't found them in the documentation but I admit that method overloading can make doc browser kind of tricky.
© Stack Overflow or respective owner