SitePoint Sponsor

User Tag List

Page 1 of 2 12 LastLast
Results 1 to 25 of 43
  1. #1
    ********* Ornithologist AtomicPenguin's Avatar
    Join Date
    May 2002
    Location
    Vancouver, BC
    Posts
    459
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    <select> browser problem

    Hi there.

    I have a sneeky little javascript problem for you guys. The following scrap of code does different things in Explorer 6 and Netscape 6.


    chosenOne = document.forms[0].city;
    city = chosenOne.options[chosenOne.selectedIndex].name;


    The code is located in a function which runs on an 'onchange' event handler. What it's trying to do is read the (new) value of the <Select> tag named 'city'. In explorer there's no problem, but Netscape refuses to read it.

    Any idea?

  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)
    Well surely you're not wanting the name property then?

    Perhaps the value ( or the innerHTML if that differs )

    Just a thought...

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

  3. #3
    ********* Ornithologist AtomicPenguin's Avatar
    Join Date
    May 2002
    Location
    Vancouver, BC
    Posts
    459
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oh, sorry. I meant name.

  4. #4
    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)
    Ok - and the name for each of the options is set?

    ( silly question - but you never know )

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

  5. #5
    ********* Ornithologist AtomicPenguin's Avatar
    Join Date
    May 2002
    Location
    Vancouver, BC
    Posts
    459
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes. [For a panic-ed moment, I had to go check!]

  6. #6
    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)
    Have you tried setting the classes of the options and
    alerting the object.className instead ?

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

  7. #7
    ********* Ornithologist AtomicPenguin's Avatar
    Join Date
    May 2002
    Location
    Vancouver, BC
    Posts
    459
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hmmm... what do you mean? Do you mean giving each <option> a class attribute?

  8. #8
    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)
    Yes - i do.

    Different attribute - different handling.

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

  9. #9
    ********* Ornithologist AtomicPenguin's Avatar
    Join Date
    May 2002
    Location
    Vancouver, BC
    Posts
    459
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Something like this?

    otherMethod = document.form[0].cities;
    alert(otherMethod);


    (where 'cities' is the class name given to all options)

    the alert() just returns an 'undefined'.

  10. #10
    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)
    other = document.forms[0].city;
    alert(other.options[other.selectedIndex].className);

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

  11. #11
    ********* Ornithologist AtomicPenguin's Avatar
    Join Date
    May 2002
    Location
    Vancouver, BC
    Posts
    459
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No luck, I'm afraid. Actually, using that code I can't even get Explorer to alert() the name, let alone Netscape. I've probably typed something wrong.

  12. #12
    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)
    show me ... url?

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

  13. #13
    ********* Ornithologist AtomicPenguin's Avatar
    Join Date
    May 2002
    Location
    Vancouver, BC
    Posts
    459
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sure, thx! But could I email it to you, or something? It's
    running on my server, and it's not terribly secure...! I don't fancy telling anyone my IP.

  14. #14
    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)
    ---=| If you're going to buy a pet - get a Shetland Giraffe |=---

  15. #15
    ********* Ornithologist AtomicPenguin's Avatar
    Join Date
    May 2002
    Location
    Vancouver, BC
    Posts
    459
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Actually, I just sent you a private message!

  16. #16
    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)
    Ok - the line:

    document.properties.area.options[document.properties.area.options.length]

    Might be a problem.

    Try doing this - in a function somewhere - once the page has been loaded ( maybe in the initiate )

    alert('Form: '+document.properties);

    That will tell you if you have a handle on the object.

    if SO - then next try alerting document.properties.area

    if NOT then try using a new refernece handler:

    function de(e){ return document.getElementById(e); }

    and instead:

    alert('Form: '+de('properties'));

    BUT - you have to set the id for all the elements you reference ( that's just good practice anyway )
    so the form properties and the selects should have their ids set the same as their names.

    I've got a sneaking suspicion that properties is a reserved
    word ( that would make sense ) and this will let us know that.

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

  17. #17
    ********* Ornithologist AtomicPenguin's Avatar
    Join Date
    May 2002
    Location
    Vancouver, BC
    Posts
    459
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm pretty sure the problem isn't there, though. I've identified where the problem lies (or where the problems BEGIN, I suppose...) and it's on line 66, right after I initialize the variable 'city'. The problem seems to be in these two lines, since if I do an alert(city) at that spot, (and in the corresponding spot in the update_area() function), Explorer happily tells me the city name, whereas Netscape gives me an 'undefined'.

  18. #18
    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)
    I wasn't identifying a problem location - i was debugging the script.

    When the page loads the area select box is empty in Netscape.

    I wanted to know if the handle to it is right or not.

    You can't start at the end of the line and work up.
    The first thing to check is that the methods you're
    using can get to the objects ... I'm not sure for definate
    that they can - so where the problem starts is irrelevant,
    the debugging method goes down the same road.

    There's no point in testing the value if you're not absolutely definate you've got a reference to the right
    object.

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

  19. #19
    ********* Ornithologist AtomicPenguin's Avatar
    Join Date
    May 2002
    Location
    Vancouver, BC
    Posts
    459
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ah! Thanks! let me have another look at your previous comments...

  20. #20
    ********* Ornithologist AtomicPenguin's Avatar
    Join Date
    May 2002
    Location
    Vancouver, BC
    Posts
    459
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Okay. Here's the stats:

    the line:
    alert('Form: '+document.properties);
    yields "Form: [object]"

    as does the other two:
    alert(document.properties.area);
    alert('Form (with de() function): '+de('properties'));

    I confess I'm feeling increasingly ignorant about all this... does the [object] mean that it's FOUND it? Or that it doesn't know what it is?

  21. #21
    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)
    Object means it's got a reference to a handle pointer to a
    namespace.
    ie: it's got it.

    I'm gonna put look at your page again in netscape and suggest some more debugging tests.

    You can take those alerts out.

    Thanks

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

  22. #22
    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)
    Code:
    function initialize() {
    
       properties.price.focus();
    
    	 initiallySelectedOne = document.forms[0].city;
    	 city = initiallySelectedOne.options[initiallySelectedOne.selectedIndex].name;
    So here - it's not getting the handle properly.

    1) put alert(initiallySelectedOne) in there after initiallySelectedOne.

    2) alert(initiallySelectedOne.options) after that.

    3) Try: alert(initiallySelectedOne.Options) since i think the options property *could* be case sensitive.

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

  23. #23
    ********* Ornithologist AtomicPenguin's Avatar
    Join Date
    May 2002
    Location
    Vancouver, BC
    Posts
    459
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    We get 'Object','Object','undefined' in that order. Any help?

  24. #24
    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)
    Yes.

    That means that you've got the objects properly... except the last one - which is a good thing. ( except i thought the second would be Object Collection )

    Ok - so a few more alerts for you ( to replace the last ones )

    1) alert(initiallySelectedOne.selectedIndex)
    that should yield a number

    2) alert(initiallySelectedOne.options[initiallySelectedOne.selectedIndex])

    3) alert(initiallySelectedOne.options[initiallySelectedOne.selectedIndex].name)

    The last one should be the problem.

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

  25. #25
    ********* Ornithologist AtomicPenguin's Avatar
    Join Date
    May 2002
    Location
    Vancouver, BC
    Posts
    459
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is interesting. On Explorer, we got: 13, [Object], Surrey. But Netscape didn't do diddly squat. I tried refreshing countless times & emptying the cache, but I got no alerts...

    Any ideas?


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
  •