SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Thread: select boxes

  1. #1
    SitePoint Member
    Join Date
    Jan 2002
    Location
    My Chair
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    select boxes

    does anyone know how i can disable a select box if on another select box the value = x

    atm all i have is this

    Code:
    var countryselect=document.forms.country.value
    
    if( countryselect ) = United Kingdom
         {
         document.forms.county.disabled=false;
         }
         else
         {
         document.forms.county.disable=true;
         }
    If i don't remember it i didn't do it

    Random

  2. #2
    Perl/Mason Guru Flawless_koder's Avatar
    Join Date
    Feb 2002
    Location
    Gatwick, UK
    Posts
    1,206
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OUCH!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

    When you use = you are making an assignment - so the results of the assignment is always 1.
    Remember that in all langauges ( scripting and programming ) at the end of the day the test must be binary.
    * NOTE - not neccessarily true in the case of using fuzzy logic - but even then it is simplified eventually.

    SO - when you put your logic of "assign this to that" it says " yep - i've done that: 1 " and so it will always run your first clause.

    Secondly - the brackets evaluate the value of a variable and then (if the operator was right) would compare it without brackets - in this some languages this still works - but it is bad practice and frowned upon.

    Thirdly - by not using inverted commas your comparisson will be treated as a variable ( or variable pair in this case ).

    So:

    if ( countryselect == 'United Kingdom') {
    ....

    Would be the right way to do it...
    However you are comparing the same field - so why bother with all this... in the onchange use:

    this.disabled=(this.value=='United Kingdom')?true:false

    or something like it.

    Hope this all helps

    Flawless
    ---=| If you're going to buy a pet - get a Shetland Giraffe |=---

  3. #3
    SitePoint Member
    Join Date
    Jan 2002
    Location
    My Chair
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    woo, that does help ta

    only prob i got is that if i change the value to a non United Kingdom one, it disables it, but if i change it back to the UK the other select box is still disabled :/

    ta for the help btw, much appreciated

    *edit* also, it's meant to disable the other select box when it's not on UK, so i changed it to
    disabled=(self.value!=='United Kingdom')?true:false
    Last edited by YCrowley; Jun 17, 2002 at 06:52.
    If i don't remember it i didn't do it

    Random

  4. #4
    The doctor is in... silver trophy MarcusJT's Avatar
    Join Date
    Jan 2002
    Location
    London
    Posts
    3,509
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    One too many equals:
    "!==" --> "!="




    M@rco


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
  •