SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    googlicious graymatter bvarvel's Avatar
    Join Date
    Sep 2002
    Location
    Katy, TX
    Posts
    956
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Disabling Form Elements

    I have a form that I need to control with code. This is what I mean... I have a drop down field called status with option of in progress, completed, and deferred. I want a second drop down field named completeddate to remain disabled UNLESS the status drop down is set to completed. Does anyone have any code that could help me establish this???

    thanks,
    brian.

  2. #2
    ********* Genius Mike's Avatar
    Join Date
    Apr 2001
    Location
    Canada
    Posts
    5,458
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    This would require JavaScript. Moving there...
    Mike
    It's not who I am underneath, but what I do that defines me.

  3. #3
    SitePoint Guru
    Join Date
    Jan 2001
    Location
    Alkmaar, Netherlands
    Posts
    710
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    <script>
    document.formName.fieldName.disabled = true;
    </script>

    <script>
    document.formName.fieldName.readonly = true;
    </script>

  4. #4
    SitePoint Wizard silver trophy
    Join Date
    May 2003
    Posts
    1,843
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <title>Frekschmekistan</title>
    </head>
    <body>
    <form>
    <select name="status" id="status" onchange="completeddate.disabled=!(this.selectedIndex==1)">
    <option>...in progress</option>
    <option>completed</option>
    <option>deferred</option>
    </select>
    <select name="completeddate" id="completeddate" disabled="disabled">
    <option>Tadzikistan</option>
    <option>Uzbekistan</option>
    <option>Frekschmekistan</option>
    </select>
    </form>
    </body>
    </html>

    <option>completed</option> is the second option, so its index position is 1 (count from zero).

  5. #5
    googlicious graymatter bvarvel's Avatar
    Join Date
    Sep 2002
    Location
    Katy, TX
    Posts
    956
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok.. i had to set the initial state of the completeddate field to disabled.. but that worked... now the completeddate field is actually 3 fields comprised of month, day, and year... how, using the code you provided:

    <select name="status" id="status" onchange="completeddate.disabled=!(this.selectedIndex==1)">

    would i disable all three fields?

  6. #6
    SitePoint Wizard silver trophy
    Join Date
    May 2003
    Posts
    1,843
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Your use of the word 'field' is confusing (to me, anyway). Be specific: what types of controls (select, text, etc.) are we talking about? Any HTML?

  7. #7
    googlicious graymatter bvarvel's Avatar
    Join Date
    Sep 2002
    Location
    Katy, TX
    Posts
    956
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    more dropdowns, but nevermind.. i got it. i do have one more related question, how would i change the selected option of one dropdown based on the selected option of another dropdown.

    for example: say i have a '%complete' dropdown with values from 10%-100%, if the user selects the 100% option, I would like the 'status' dropdown to automatically be set to completed.

    thanks for the help.
    brian.


Bookmarks

Posting Permissions

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