bravo14 Posted July 3, 2013 Share Posted July 3, 2013 I want to be able to disable a payment option if a user selects Delivery as an option. the function I have is function disableCOD(){ if (document.getElementById('optDelivery').value == 'optDel') { document.getElementById('optPaypal').checked = 'true'; document.getElementByName('optPayment').disabled='true'; } else{ document.getElementByName('optPayment').disabled='false'; } } The form details are <table width="550" border="0" align="center" cellpadding="5" cellspacing="1" class="entryTable"> <tr> <td width="150" class="entryTableHeader">Delivery Method </td> <td class="content"> <input name="optDelivery" type="radio" id="optSwindon" value="Collect from Birmingham" onclick="disableCOD()"/> <label for="optBirmingham" style="cursor:pointer">Collect from Birmingham</label> <input name="optDelivery" type="radio" id="optSomerset" value="Collect from Somerset" onclick="disableCOD()"/> <label for="optSomerset" style="cursor:pointer">Collect from Somerset</label> <input name="optDelivery" type="radio" value="Delivery" id="optDel" onclick="disableCOD()"/> <label for="optDel" style="cursor:pointer">Delivery</label></td> </tr> </table> <table width="550" border="0" align="center" cellpadding="5" cellspacing="1" class="entryTable"> <tr> <td width="150" class="entryTableHeader">Payment Method </td> <td class="content"> <input name="optPayment" type="radio" id="optPaypal" value="paypal" checked="checked"/> <label for="optPaypal" style="cursor:pointer">Paypal</label> <input name="optPayment" type="radio" value="cod" id="optCod" /> <label for="optCod" style="cursor:pointer">Cash on Delivery</label></td> </tr> </table> The error I get is document.getElementById(...) is null where am i going wrong? Quote Link to comment https://forums.phpfreaks.com/topic/279824-disable-field-based-on-value-of-option-group/ Share on other sites More sharing options...
Irate Posted July 3, 2013 Share Posted July 3, 2013 Check again. First you refer to the id as optDelivery, but in your HTML it is named optDel. Quote Link to comment https://forums.phpfreaks.com/topic/279824-disable-field-based-on-value-of-option-group/#findComment-1439210 Share on other sites More sharing options...
White_Lily Posted July 4, 2013 Share Posted July 4, 2013 and to add to irates answer, you may also want to check the comparison of the value in the input field to, as you stated if(document.getElementById('optDelivery').value == 'optDel') when in actual fact it is (and always will be unless you change it elsewhere) equal to Delivery not optDel. Quote Link to comment https://forums.phpfreaks.com/topic/279824-disable-field-based-on-value-of-option-group/#findComment-1439458 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.