Question Details    

   Question

Time: 15:49 - Oct 30, 2007     Asked by: kassidi6      Status: Answered      Points: 75   

i need help with enabling/disabling text fields

I looked at one your older posts and im currently using your following script:
<html>
<head>
<title>Test</title>
<script type="text/javascript">
function disable_controls( state) {
var frm = document.forms[0] ;
var len = frm.elements.length ;
var cnt = 0 ;
for ( var i=0; i < len; i++) {
var elem = frm.elements[i] ;
if (elem.type != "hidden") {
elem.disabled = state ;
}
}
}
</script>
</head>
<body>
<button onclick="disable_controls( false)">Enable</button>
<button onclick="disable_controls( true)">Disable</button>
<br>

<form action="yours" method="POST" enctype="application/x-www-form-urlencoded">
<input name="t1" disabled size="10" value="ini val" type="text">
<br>
<textarea name="t2" cols="10" disabled >abc
def</textarea> </form>
</body>
</html>
--------------------------------------------------------
The way i'm actually using it is instead of using buttons to disable/enable the following fields, i'm using a radio type field. Yes (is the Enable value) and No (Disable value). The problem i'm having is that when i a select No, it will gray out radio field. I can't then go back and select Yes.
I tried tweaking the code a bit, but with no success. Is there a way to workaround this?
Thank you very much.

 
  • Ask a New Question
  • Become a Quomon Expert
  • Current Categories

     

    Other Questions Needing Answers


       
     

    Answer Discussion

    Answer Discussion

    Answer Summaries

    Answer Summary

     
     

    Question & Answer System for Websites and Corporate Intranets

  • Save your corporation money by having common business problems solved once
  • Drive a significant amount of new traffic to your website, products, and services
  • Advertisement

    oops, i forgot to mention that i changed the code of the html body to be as follow:
    -------------------------------------------------------------------------------
    -------------
    <body>

    <form action="yours" method="POST" enctype="application/x-www-form-urlencoded">

    <input type="radio" value="Yes" name="Marketing_IC_Contact_Info__em" onclick="disable_controls( false)">Yes
    <input type="radio" value="No" name="Marketing_IC_Contact_Info__em" onclick="disable_controls( true)">No
    <br>
    <input name="t1" disabled size="10" value="ini val" type="text">
    <br>
    <textarea name="t2" cols="10" disabled >abc
    def</textarea> </form>
    </body>
    -------------------------------------------------------------------------------
    ---------------------------------
    The reason it's behaving the way i mentioned earlier is because i moved the radio field inside the form, which is how we want it to be.

    Any help on how to get it to work by having the radio field inside the form will be much appreciated.

    Thank you.

    Expert:

    kassidi6

    Date:

    Oct 30, 2007

    Time:

    16:05

     

    Votes: Good (0) | Bad (0)
    Login to rate this answer

    kassid,

    In your javascript, you're iterating through all the controls and disabling them, including your radio button. That's why it's giving you the behavior you're experiencing.

    Basically, you're still going to iterate all the controls in the form, but when you get to your radio button(s), you're going to leave them enabled by ignoring them...

    if (elem.type != "hidden") {
    if (elem.type != "radio") {
    elem.disabled = state ;
    }
    }

    That will keep all radio buttons enabled. You can refine it by looking at the name or adding an id property and excluding the radio button(s) programmatically.

    I hope this helps,
    Ric

    Expert:

    rcastagna

    Date:

    Nov 07, 2007

    Time:

    07:35

     

    Votes: Good (0) | Bad (0)
    Login to rate this answer

    missed that. works out fine now. Thank you.

    Expert:

    kassidi6

    Date:

    Nov 07, 2007

    Time:

    16:46

     

    Votes: Good (0) | Bad (0)
    Login to rate this answer

    For a limited time save $10 off CA Internet Security Suite 2008

    Question Answered

    This question has been answered, and points have been rewarded to the following experts:

    rcastagna: 75

    You're welcome however to comment or give additional information or if you wish, you have the ability to write an Answer Summary for this question by clicking on the "Answer Summaries" Tab.

    No summaries have been submitted yet. Want to be the first?



    Respond to this question:

    New User

      Email:

    Upon submission of this form, you will automatically be registered as a Quomon user and we will send your login information to this address

    Registered User

    Username:

    Password:


    Forgotten Password

    Enter your email address below and we will resend your login information to you.

    Email:


     


     

    New User

      Email:

    Upon submission of this form, you will automatically be registered as a Quomon user and we will send your login information to this address

    Registered User

    Username:

    Password:


    Forgotten Password

    Enter your email address below and we will resend your login information to you.

    Email:


     

       

    "Psst, Quomon is a great site. Pass it on."     Tell a Friend  |   Link To Us  |   Save to Delicious  |   Digg! Digg it


    All Questions


    Language Options

    English:

    www.quomon.com

    Español:

    www.quomon.es

    Quomon Blog

    blog.quomon.com

    Sponsors

    Questions and Answers Software
    Real Estate Postcards
    Marketing Fulfillment