SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot
    Join Date
    Dec 2010
    Posts
    167
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Need Expected Identifier IE

    This works in firefox, but IE says I need an Expected identifier with

    fullname_msg.for = 'fullname';

    IE specifically shows that it doesn't like for. Any reason why this happens?

  2. #2
    SitePoint Guru
    Join Date
    Apr 2006
    Posts
    802
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    There are 'reserved' words in javascript that many browsers will not allow to be used as identifiers in methods or property names.
    Some browser implementations allow some of them, others add their own reserved words. I just avoid them.

    There are some 'safe' aliases-
    'htmlFor' for 'for', 'className' for 'class' and 'styleFloat' or 'cssFloat' for 'float' are common examples.

    abstract,boolean,break,byte,case,catch,char,class,const,continue,
    debugger,default,delete,do,double,else,enum,export,extends,false,
    final,finally,float,for,function,goto,if,implements,import,in,
    instanceof,int,interface,let,long,native,new,null,package,private,
    protected,public,return,short,static,super,switch,synchronized,this,
    throw,throws,transient,true,try,typeof,var,void,volatile,while,with,yield;

  3. #3
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,603
    Mentioned
    24 Post(s)
    Tagged
    1 Thread(s)
    So for it to work properly without a reserved word clash it needs to be written as:

    fullname_msg.htmlFor = 'fullname';
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">


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
  •