sainture
8/13/2015 - 10:37 AM

jQuery Form element manipulation

jQuery Form element manipulation

/*
Radio buttons 
  Uses checked = "checked" or in html5 just 'checked' property
  Get selected Radio button value - find radio button with checked attribute and use val() 
  Set selected Radio button value - find radio button by name & value and then set attribute 'checked'
*/
// GET
$('input[name=radioName]:checked').val()

// SET -- Option 1
var radioValue = 5;
$("input[name=radioName][value=" + radioValue + "]").attr('checked', 'checked');

// SET - Option 2 (preferred)
$("input[name=radioName][value=" + radioValue + "]").prop('checked', true);

// Attach onchange event  ()
jQuery("input[name=re_condition]:radio").change(function () {
});

/*
Check boxes
  Uses checked = "checked" or in html5 just checked property
*/


/*
Drop downs - Select Options
  Uses selected = "selected" or in html5 just 'selected' property
*/

// GET value
$('#dropDownId').val();

// GET text
$('#dropDownId :selected').text();

// SET value
$('#dropDownId').val("Value_You_Want_To_Set");