Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Nov 2005
    Posts
    750
    Thanks
    138
    Thanked 1 Time in 1 Post

    Option explicit error

    Hello

    If I do not insert a doctype (strict or loose are the types I have tried), my Web form page seems to work fine. But when I do, I get the following error:

    Microsoft VBScript compilation error '800a0400'

    Expected statement

    /contact_us.asp, line 9

    option explicit
    I would be happy to leave out the doctype, but I am trying to use the CSS 'focus' snippet

    Code:
    input:focus
    {
    background-color:yellow;
    and for it to work,
    :focus to work in IE8, a DOCTYPE must be declared
    according to the W3 Schools site:

    http://www.w3schools.com/cssref/sel_focus.asp

    How would I get round that problem, please?

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    26,027
    Thanks
    79
    Thanked 4,436 Times in 4,401 Posts
    ASP requires the OPTION EXPLICIT to be first on the page, excepting for <%@ xxx %> declarations.

    So you really do need to put it before the DOCTYPE.

    And it really is perfectly okay to do so.

    Remember *NO* code in <%...%> tags is seen directly by the browser. Only if you Response.Write something from within <%...%> is it sent to the browser.

    So if you write
    Code:
    <%@ Language="VBScript" %>
    <% OPTION EXPLICIT %>
    <!DOCTYPE html ... >
    or even if you prefer for some reason to do
    Code:
    <%@ Language="VBScript" %>
    <% OPTION EXPLICIT %>
    <% Response.Write "<!DOCTYPE html ... >" %>
    the browser will never see anything prior to the <!DOCTYPE...>.

    And it is only what the browser sees that matters for any HTML tags, including <!DOCTYPE ...>
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • Users who have thanked Old Pedant for this post:

    SteveH (04-27-2012)

  • #3
    Regular Coder
    Join Date
    Nov 2005
    Posts
    750
    Thanks
    138
    Thanked 1 Time in 1 Post
    Hello Old Pedant

    ASP requires the OPTION EXPLICIT to be first on the page, excepting for <%@ xxx %> declarations.

    So you really do need to put it before the DOCTYPE.
    I think that needs emphasising sometimes - I have seen a few Web sites that state the DOCTYPE goes first.

    My page is fine after your suggestion.

    Many thanks.

    Steve

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    26,027
    Thanks
    79
    Thanked 4,436 Times in 4,401 Posts
    Quote Originally Posted by SteveH View Post
    I have seen a few Web sites that state the DOCTYPE goes first.
    If you don't use <%@ page %> directives and you don't use <% option explicit %>, which many many many sites do not, then yes, it goes first.

    But, again, all that really matters is that it goes first in what the browser sees, not necessarily what the ASP (or PHP or JSP or ASP.NET) processor sees.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Posting Permissions

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