Jump to content

Disable field based on value of option group


bravo14

Recommended Posts

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.