Jump to content

[SOLVED] Enabling a disabled textbox within a form


vozzek

Recommended Posts

Hi everyone,

 

Java newbie here, so please bear with me.  I really tried this 10 different ways by now, and only came here when I was absolutely stumped.

 

I've got a form (form1) with 2 fields.  One is a Y/N radio button called 'customizable'.  The other is a text field called 'character_limit'.

 

I want 'customizable' defaulted to 'N' (already have that) with the 'character_limit' field disabled.  But when 'customizable' is clicked to 'Y', I want 'character_limit' to be enabled.  I've tried this directly with the following code:

 

<tr valign="baseline">

      <td align="right" valign="top" nowrap="nowrap">Customizable:</td>

      <td valign="baseline"><table>

        <tr>

          <td><input onclick="document.character_limit.disabled = false" type="radio" name="customizable" value="Y" />

            Yes</td>

        </tr>

        <tr>

          <td><input onclick="document.character_limit.disabled = true" type="radio" name="customizable" value="N" checked="N" />

            No</td>

        </tr>

      </table></td>

    </tr>

    <tr valign="baseline">

      <td nowrap="nowrap" align="right">Character Limit:</td>

      <td><input name="character_limit" type="text" value="" size="32" maxlength="3" disabled="disabled"/>

       

      </td>

    </tr>

 

I also tried creating a function that looks like this:

 

<script type="text/javascript">

<!--

 

function disable_enable(){

if (document.all || document.getElementById){

if (document.form1.customizable.value=='Y')

document.form1.character_limit.disabled=false

else

document.form1.character_limit.disabled=true

}

}

</script>

 

The function looks good, but I'm not sure exactly where (or how) to place the code that calls that function.  Sorry if this is a pretty elementary question, but I'm still learning.

 

Thanks in advance for the help.

 

Link to comment
Share on other sites

Ahhhhh, crap!  Sometimes the most obvious things are the hardest to solve.

 

You nailed it.  I changed:

 

input onclick="document.character_limit.disabled = true"

to

input onclick="document.form1.character_limit.disabled = true"

 

and I am now a happy camper.  Thanks fenway!

 

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.

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