variable with a period in the name

Discussion in 'Javascript' started by rphooper3@gmail.com, Sep 14, 2007.

  1. Guest

    Hello,
    for compatibility reasons I have a variable in javascript with periods
    in its name, it is based on a hostname and I need to tie that
    information to the function.
    the variable is function_www.hostname.com
    The problem is when I try to run a simple javascipt program on it, the
    script fails, probably because of the way javascript uses periods, but
    if I remove the periods the script works.
    is there anyway to inclose full hostnames within variable names?

    here is a sample of the code:
    function_www.hostname.com =
    document.userchange.function_www.hostname.com.checked;
    if (! function_www.hostname.com) {
    if (confirm("Do you want this?")) {
    document.userchange.function_www.hostname.com.checked = true;
    }
    }


    INPUT TYPE="checkbox" NAME="function_www.hostname.com"
     
    , Sep 14, 2007
    #1
    1. Advertising

  2. RobG Guest

    wrote:
    > Hello,
    > for compatibility reasons I have a variable in javascript with periods
    > in its name, it is based on a hostname and I need to tie that
    > information to the function.
    > the variable is function_www.hostname.com
    > The problem is when I try to run a simple javascipt program on it, the
    > script fails, probably because of the way javascript uses periods, but
    > if I remove the periods the script works.
    > is there anyway to inclose full hostnames within variable names?
    >
    > here is a sample of the code:
    > function_www.hostname.com =


    You can't use dots in an identifier (ECMAScript Spec, section 7.6). It
    is entirely unnecessary in a local variable anyway, you could use x or z
    or whatever is meaningful to you.


    > document.userchange.function_www.hostname.com.checked;


    Guessing that userchange is the name of a form:

    document.userchange.elements['function_www.hostname.com'].checked;


    <URL: http://www.jibbering.com/faq/#FAQ4_25 >



    > if (! function_www.hostname.com) {
    > if (confirm("Do you want this?")) {
    > document.userchange.function_www.hostname.com.checked = true;
    > }
    > }


    You might consider something like:

    var el = document.userchange.elements['function_www.hostname.com'];
    if (!el.checked) {
    if (confirm("Do you want this?")) {
    el.checked = true;
    }
    }


    --
    Rob
    "We shall not cease from exploration, and the end of all our
    exploring will be to arrive where we started and know the
    place for the first time." -- T. S. Eliot
     
    RobG, Sep 14, 2007
    #2
    1. Advertising

  3. Guest

    I wasnt familiar with elements['variable'] that worked perfectly.

    Thank you very much,
    Robert
     
    , Sep 14, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    4
    Views:
    324
    Laurent Bugnion [MVP]
    Jan 3, 2007
  2. Bobby Chamness
    Replies:
    2
    Views:
    2,441
    Joe Smith
    Apr 22, 2007
  3. mfglinux
    Replies:
    11
    Views:
    751
    Roberto Bonvallet
    Sep 12, 2007
  4. David Filmer
    Replies:
    19
    Views:
    280
    Kevin Collins
    May 21, 2004
  5. Steve Swift
    Replies:
    4
    Views:
    104
    Steve Swift
    Sep 2, 2006
Loading...

Share This Page