Something like this as you are not using jQuery:
// Get radios
var rad = document.getElementsByName('mailForOrder_no');
// Disable / Enable element based on value
function disable_by_radio(w, id) {
document.getElementById(id).disabled =
w.checked && w.value === "No";
}
// Update by event
rad[0].onchange = function (e) { disable_by_radio(this, 'mailForOrder'); };
rad[1].onchange = function (e) { disable_by_radio(this, 'mailForOrder'); };
// Initial update
disable_by_radio(rad[1], 'mailForOrder');
With this HTML:
<input type="text" id="mailForOrder" />
<input name="mailForOrder_no" type="radio" value="Yes" />Yes
<input name="mailForOrder_no" type="radio" value="No" checked />No
As you are not using jQuery, the $()
part, and why your code does not work, is impossible to explain as it is not part of pure Javascript.
In short, a wild guess:
Radio buttons does not have a function named checked()
but an attribute. If the $()
part of your code only passes the object on, then trying to call an attribute would result in an error.