Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > variable with a period in the name

Reply
Thread Tools

variable with a period in the name

 
 
rphooper3@gmail.com
Guest
Posts: n/a
 
      09-14-2007
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.chec ked;
if (! function_www.hostname.com) {
if (confirm("Do you want this?")) {
document.userchange.function_www.hostname.com.chec ked = true;
}
}


INPUT TYPE="checkbox" NAME="function_www.hostname.com"

 
Reply With Quote
 
 
 
 
RobG
Guest
Posts: n/a
 
      09-14-2007
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.chec ked;


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.chec ked = 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
 
Reply With Quote
 
 
 
 
rphooper3@gmail.com
Guest
Posts: n/a
 
      09-14-2007
I wasnt familiar with elements['variable'] that worked perfectly.

Thank you very much,
Robert

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
"Variable variable name" or "variable lvalue" mfglinux Python 11 09-12-2007 03:08 AM
adding a variable name to a hash to name is part of the variable name Bobby Chamness Perl 2 04-22-2007 09:54 PM
Create page name 'on the fly' & Use of Period / Stop / . in url iam247@gmail.com ASP .Net 4 01-03-2007 11:12 PM
VoIPCheap/Stunt/SIPDiscount/Et.al - Mobile - Top-up Expiry Period -- Campaign for Correct Expiry Period on Finarea VOIP Service Mobile Top-Ups News Reader UK VOIP 16 06-26-2006 05:03 PM
How do I scope a variable if the variable name contains a variable? David Filmer Perl Misc 19 05-21-2004 03:55 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57