Results 1 to 4 of 4
  1. #1
    Silver Lounger
    Join Date
    Jan 2001
    Location
    Indianapolis, Indiana, USA
    Posts
    1,862
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Cross Browser JavaScript tips

    I recently discovered the answer to something that had baffled me for months and I thought that others might benefit from the same information.

    I usually do my web application development and testing exclusively with Microsoft products (Visual Studio 7 and IE 6). Occasionally, I might test some things with Netscape 4.79 or 6.2 to see if it works properly. There was always one technique that worked very easily in IE, but always failed in Netscape

  2. #2
    Uranium Lounger
    Join Date
    Jan 2001
    Location
    Cincinnati, Ohio, USA
    Posts
    7,089
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Cross Browser JavaScript tips

    Mark, even though there hasn't been a response....I think this information is second to none. Thanks a million for your endless hard work and contributions.
    -Mark

  3. #3
    2 Star Lounger
    Join Date
    Apr 2001
    Location
    Coppell, Texas, USA
    Posts
    168
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Cross Browser JavaScript tips

    Mark,

    That's a great tip. In general, IE always seems to be a little "smarter" than Netscape. When I work with other developers that are not familiar with cross-browser development, it's interesting to see little things like this tripping them up. Here's another one that almost everyone gets "wrong":

    If you've got a form with a SELECT element (a drop-down list), you would think that you can get the current value as follows:

    var x = document.form1.select1.value;

    And you'd be right... in IE (or Opera 6.x). But Netscape doesn't use the value property on the select element - it's always null. You need to use the complete reference to the value of the selected option, like this:

    var x = document.form1.select1.options[document.form1.select1.selectedIndex].value;

    Not very intuitive. Value can be a tricky attribute in other places too. A checkbox with an assigned value has that value whether or not it's checked. When the form is submitted, the value gets returned only if the checkbox's checked property is true.

    I wrote a getVal function that inspects an element to determine it's type and returns the "current value" (what would show up in the data if the form was being submitted). It's pretty straight-=forward for everything but radio button groups - those are just a real pain to identify. If anyone's interested, I'll start a thread with the code and maybe we can fix it. It's very useful for pages where an element that's normally displayed is sometimes a hidden field, not to mention simplifying the code for getting the current value of a SELECT element.

  4. #4
    Silver Lounger
    Join Date
    Jan 2001
    Location
    Indianapolis, Indiana, USA
    Posts
    1,862
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Cross Browser JavaScript tips

    Hi Charlie,
    That's some great information! I've noticed some issues with the SELECT element's 'value' property. I usually only test to make sure it's not empty, but it's nice to know you can read the actual value with the statement you provided.

    Checkboxes and Radio groups are often a pain - however, I usually find myself dealing with them on the Server-side (with ASP) rather than client side (with JavaScript).

    By all means, please feel free to share your function(s) - that would be GREAT!! <img src=/S/joy.gif border=0 alt=joy width=23 height=23>

    Thanks

Posting Permissions

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