SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Addict
    Join Date
    Sep 2008
    Posts
    341
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    www.page-test.co.uk/ie.html works on every browser except IE 7/8

    http://www.page-test.co.uk/ie.html

    The above small script (couple of lines) works in every browser except IE7/8.

    Is there an alternative?

    Btw. A framework I use passes values from PHP to the client using this method.

  2. #2
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    5,941
    Mentioned
    215 Post(s)
    Tagged
    12 Thread(s)
    Hi,
    The problem is that the ternary operator doesn't work in IE7/IE8 with an undeclared variable.
    You can test this by adding
    Code JavaScript:
    var value_a = "";
    var value_b = "";
    to the beginning of your script, then as you will see, everything works as expected in IE7/IE8.

    However, this is probably not the ideal solution.
    Maybe you could do it like this instead:

    Code JavaScript:
    var value_a = (document.getElementById( 'value_a' )) ? document.getElementById('value_a').content : "";
    var value_b = (document.getElementById( 'value_b' )) ? document.getElementById('value_b').content : "";
    alert(value_a);
    alert(value_b);

    This should work in all browsers.
    HTH


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
  •