Results 1 to 14 of 14

Thread: [Resolved] HTML/Javascript: Disable Form Fields?

  1. #1

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256

    [Resolved] HTML/Javascript: Disable Form Fields?

    I have a set of three options that a user can pick. On the third option, when it is selected, I want an input field to be enabled, and if one of the other two are selected, I want this field to be disabled.

    Is this possible? And if so, how?
    Last edited by The Hobo; Oct 17th, 2003 at 11:51 PM.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  2. #2
    Lively Member morrowasted's Avatar
    Join Date
    Aug 2003
    Location
    Houston, TX
    Posts
    118
    well, don't they have a disabled property (form objects)?

    <option onClick="document.all.whatever.disabled='true'">

    or false whenever necessary, or am i way off?

    -morrowasted

  3. #3
    Frenzied Member dj4uk's Avatar
    Join Date
    Aug 2002
    Location
    Birmingham, UK Lobotomies: 3
    Posts
    1,131
    I've been using the following JavaScript function:

    function email_access_Clicked(enabled) {
    if (enabled == 1) {
    document.network_delete_user.email_access.disabled = false
    } else {
    document.network_delete_user.email_access.disabled = true
    }
    }

    Where network_delete_user is the form name and email_access_disabled is the form element that needs to be disabled/enabled.

    Which is used as follows:

    <tr>
    <td class="print_cell"><b>E-mail: (Mail folders, PAB)</b></td>
    <td class="print_cell" align="center"><input type="radio" name="email_delete" value="1" onClick="javascript:email_access_Clicked(0);"></td>
    <td class="print_cell" align="center"><input type="radio" name="email_delete" value="0" onClick="javascript:email_access_Clicked(1);">
    <select name="email_access" class="holiday-form-submit">
    <option value="0">Select User</option>
    </select></td>
    </tr>

    Note that this doesn't work in Netscape 4.7 and that if you disable a form element its value is not passed when the form is submitted - it is treated like it doesn't exist.

    DJ

  4. #4

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Works great. Thanks.

    Originally posted by dj4uk
    Note that this doesn't work in Netscape 4.7
    Does it give a javascript error, or just not work?
    My evil laugh has a squeak in it.

    kristopherwilson.com

  5. #5
    Frenzied Member dj4uk's Avatar
    Join Date
    Aug 2002
    Location
    Birmingham, UK Lobotomies: 3
    Posts
    1,131
    As far as I remember it was because Netscape 4.7 doesn't support disabled form elements. Netscape 6+ is fine tho'

    DJ

  6. #6

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    I understand that.

    Does it give a javascript error is what I want to know.

    I don't want my program to be giving people javascript errors, so I need to know if it produces an error, or if it just doesn't work.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  7. #7

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Well, I'll have to download 4.7 and see for myself. Thanks.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  8. #8
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    May I recommend the use of document.getElementById? It's more up to the standard.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  9. #9
    Frenzied Member dj4uk's Avatar
    Join Date
    Aug 2002
    Location
    Birmingham, UK Lobotomies: 3
    Posts
    1,131
    True. But that won't work with Netscape 4.7?

  10. #10
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    The code he has doesn't either.
    And I for one have given up supporting NS4. It's so outdated and so little used (<2% I believe), it simply isn't worth it.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  11. #11
    Frenzied Member dj4uk's Avatar
    Join Date
    Aug 2002
    Location
    Birmingham, UK Lobotomies: 3
    Posts
    1,131
    Yes also true - up until last week we were supporting 4.7 but after checking stats for various we have dropped support. I only mentioned it as he seemed to want it to work for 4.7.

  12. #12

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Originally posted by CornedBee
    May I recommend the use of document.getElementById? It's more up to the standard.
    What would that look like?

    Code:
    document.getElementById['field_name'].disabled = ?
    Or something else?
    My evil laugh has a squeak in it.

    kristopherwilson.com

  13. #13
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    () instead of [].
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  14. #14

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Thanks.
    My evil laugh has a squeak in it.

    kristopherwilson.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width