Jump to content

Disable field based on value of option group


bravo14
 Share

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

This thread is more than a year old.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • 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.