variable with a period in the name

R

rphooper3

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"
 
R

RobG

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;
}
}
 
R

rphooper3

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

Thank you very much,
Robert
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top