Enabling certain text fields corresponding to the selected radio button

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • padmapriya
    New Member
    • Aug 2008
    • 3

    Enabling certain text fields corresponding to the selected radio button

    I need to create three radio buttons and when the radio button is clicked, the corresponding text fields such as 3 different address types should get activated.
    If i clicked the first radio button, the text field corresponding to that should be enabled and the other two address type fields should be disabled. This is working fine for the first radio button. But for the other two radio buttons also, the first address type field only gets enabled. The corresponding address type fields for second and third radio button is not getting activated.

    Please help me to solve this issue in javascript

    Thanks in advance.
  • gits
    Recognized Expert Moderator Expert
    • May 2007
    • 5388

    #2
    please post the code that makes the problem ... so that we may have a closer look at it and could give you hints to fix that problem ...

    kind regards

    Comment

    • padmapriya
      New Member
      • Aug 2008
      • 3

      #3
      Thanks a lot for your quick response...Hope i had given the clear picture of what i said. Please go through it and provide me the solution.


      [HTML]<html>
      <head>
      <title></title>
      <script type="text/javascript">
      function init(){
      //disable text fields
      var f = document.inputF orm;
      f.CurrentAddres s.disabled = true;
      f.PermanentAddr ess.disabled = true;
      f.WorkAddress.d isabled = true;
      }

      function enableDisable(o Frm, enabledFldName, disabledFldName s){
      oFrm.elements[enabledFldName].disabled = false;
      if (disabledFldNam es instanceof Array){ //multiple field names
      var len = disabledFldName s.length;
      for (var i=0; i<len; i++){
      oFrm.elements[disabledFldName s[i]].disabled = true;
      }
      }
      else{ //single field name
      oFrm.elements[disabledFldName s].disabled = true;
      }
      }
      </script>


      <td>

      <input type="radio" name="dedupe" value="dedupe1" onclick="enable Disable(this.fo rm, 'CurrentAddress ', 'PermanentAddre ss', 'WorkAddress')" /></td>
      <td><input name="CurrentAd dress" type="text" /></td>

      <input type="radio" name="dedupe" value="dedupe2" onclick="enable Disable(this.fo rm, 'PermanentAddre ss','CurrentAdd ress', 'WorkAddress')" /></td>
      <td><input name="Permanent Address" type="text" /></td>

      <input type="radio" name="dedupe" value="dedupe3" onclick="enable Disable(this.fo rm, 'WorkAddress',' CurrentAddress' , 'PermanentAddre ss' )" /></td>
      <td><input name="WorkAddre ss" type="text" /></td>
      [/HTML]
      ***The current address, permanent address and work address contain sub- fields such as address line1, address line 2, address line 3, city, pincode etc..
      Last edited by gits; Aug 12 '08, 07:12 AM. Reason: added code tags

      Comment

      • vee10
        New Member
        • Oct 2006
        • 141

        #4
        Hi,

        in the script function u are comparing the disabledFldName s as an instance of array or not but while calling the fuction u r sending it as an array so always it will be false so the previous one which is enabled will not disabled

        forexample u first select the radio button 2 so permant address one will be enabled now u selected the radio button 3 and now the disabledFldName s will be only the currentAddress not the array so it is not an instance so only the currentAddress will be disabled not the permant address

        i hope u understood what i am saying

        Code:
        <input type="radio" name="dedupe" value="dedupe1" onclick="enableDisable(this.form, 'CurrentAddress', new Array('PermanentAddress', 'WorkAddress'))" />
        <input name="CurrentAddress" type="text" disabled="disabled" />
        
        <input type="radio" name="dedupe" value="dedupe2" onclick="enableDisable(this.form, 'PermanentAddress',new Array('CurrentAddress', 'WorkAddress'))" />
        <input name="PermanentAddress" type="text" disabled="disabled" />
        
        <input type="radio" name="dedupe" value="dedupe3" onclick="enableDisable(this.form, 'WorkAddress',new Array('CurrentAddress', 'PermanentAddress') )" />
        <input name="WorkAddress" type="text" disabled="disabled" />
        Last edited by gits; Aug 12 '08, 07:12 AM. Reason: useless quote

        Comment

        • padmapriya
          New Member
          • Aug 2008
          • 3

          #5
          Once again thanks for the reply. Still the first radio button is only working. Even i clicked the other two, the first text field(Current address) is only activated.

          I guess u understood like what radio button i clicked first is enabling its corresponding text field. But its not so. Whatever i clicked first, only the first radio button is working. Even If i clicked the second radio button first, the text fields of first button (Current address) is only enabled. So, waiting for the solution again.

          Comment

          Working...