Page 1 of 2 12 LastLast
Results 1 to 10 of 19

Thread: Javascript for select box help

  1. #1
    Join Date
    Jun 2006
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Javascript for select box help

    Hi all,
    What I am trying to do is when the user uses the select box and slecects the option of Add/Delete it pops up a div.

    As you can see in the code it works. What is bothering me is that when I select a regular option (i.e Architectural or Mechanical) it produces a javascript error. Can any one help me out so it does not show this error?

    ** note I am only seeing it say it has an error in IE**

    sample of what I am doing is located here

    http://www.stevetompkins.com/dropdown.html

    Thanks in advance

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Move the code in the <select>'s onchange event to the <option>'s onclick event.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  3. #3
    Join Date
    Jun 2006
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    so you are saying take

    onchange="hideAll(); changeDiv(this.options[this.selectedIndex].value,'block');"
    and change it to

    onclick="hideAll(); changeDiv(this.options[this.selectedIndex].value,'block');"
    and move it from the select tag down to the option tag?

    I tried that with no success =(

  4. #4
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    You haven't done it on your demo page.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  5. #5
    Join Date
    Jun 2006
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    sorry about that I just made the change local. if you visit it now it is updarted with your suggestion.

    Thanks

  6. #6
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Revert your code, and let's just add some basic sanity checking:
    Code:
    function changeDiv(the_div,the_change)
    {
      if(!document.getElementById(the_div)) return;
      document.getElementById(the_div).style.display=the_change;
    }
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  7. #7
    Join Date
    Jun 2006
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Awesome! I think that did the trick. I really appreciatet your help.

    Thanks!

  8. #8
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Just to let you know... that doesn't work in Safari. I'm not too surprised, though. It's JS implementation is different than FF/IE.

    Also, I'd recommend having a "Choose one below" or something as the first item in the select menu, so that you don't have Architectural already up, but no div, causing confusion.

    EDIT: Um.... this doesn't seem to work in FF either.
    ...or IE (5/mac).
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  9. #9
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Basically, doesn't work?
    It's JS implementation is different than FF/IE.
    It uses KHTML, insofar as I'm aware, so it's most similar to Konqueror. However, it tends to be several versions of the component behind Konqueror.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  10. #10
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Well, I'm not talking about html. The html doesn't behave that differently... not in a noticably bad way, really.
    The javascript just varies from other browsers.
    Perhaps the javascript is part of the implemenation of KHTML; I wouldn't know.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

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
  •