p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


Go Back   p2p.wrox.com Forums > Web Programming > JavaScript > Javascript
I forgot my password Register Now
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Javascript General Javascript discussions.

Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript section of the Wrox p2p Programmer to Programmer discussion community. This is a community of more than 40,000 computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining our free Wrox p2p community you can post your own programming questions and respond to other programmers’ questions. Registered users also don't have to see the ads that are displayed to guests. Registration is fast, simple and absolutely free so please, join today!
Join today and post to win prizes! Post more to increase your chances of being Wrox’s top poster of the month.

Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old May 6th, 2005, 05:07 AM
Authorized User
 
Join Date: Apr 2005
Location: , , United Kingdom.
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Default Problem with variable names

Hi All

I've never run into something like this before hope someone out there can help.

Heres the problem:

When I declare....
Code:
var 847ba3ec_369e_4a57_8475_83faffd1187e = 'as';
It throws a big fat javascript error...

But this line doesn't...
Code:
var bcfaeec0_3c34_4076_8abb_41d9b960c117 = 'as';
So why do some GUIDs work as var names but some dont? Is there some kind of variable naming thing I should know about?

Heres why Im doing it: (if you care ;P)
I am creating a menu tree from sections/categories but because sections might have the same name, they need to use a unique name for the variable. I have GUIDs as the ID in the tables and so was using that as the javascript variable name...

Thanks for any help!!

:D



Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #2 (permalink)  
Old May 6th, 2005, 05:11 AM
Authorized User
 
Join Date: Apr 2005
Location: , , United Kingdom.
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Default

*vomit*

You cant start a javascript variable with a numeric.

SUCH an idiot!

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #3 (permalink)  
Old May 6th, 2005, 04:46 PM
nzakas's Avatar
Wrox Author
Points: 644, Level: 9
Points: 644, Level: 9 Points: 644, Level: 9 Points: 644, Level: 9
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2004
Location: Peabody, MA, USA.
Posts: 191
Thanks: 0
Thanked 2 Times in 2 Posts
Default

Though colorfully-worded, shenku is correct. Variable names can only begin with a letter, and underscore, or a dollar sign ($). To save yourself the trouble, you may just want to always prepend "GUID_" to the front of your variables, such as:

Code:
var GUID_bcfaeec0_3c34_4076_8abb_41d9b960c117 = 'as';
Nicholas C. Zakas
Author, Professional JavaScript for Web Developers (ISBN 0764579088)
http://www.nczonline.net/
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
generate variable names dinamycally gcorcuera Classic ASP Basics 7 May 21st, 2007 10:53 AM
problem with session variable prabhatsriva01 ASP.NET 2.0 Professional 3 May 10th, 2007 12:41 PM
dynamic variable/object names TheBFJ Excel VBA 2 November 13th, 2006 07:11 AM
Session Variable Problem kwilliams ASP.NET 2.0 Basics 0 June 12th, 2006 12:56 PM
problem in showing froms by using names in VB.Net arctica82 Pro VB.NET 2002/2003 1 April 15th, 2005 04:15 PM



All times are GMT -4. The time now is 10:10 PM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
© 2008 Wiley Publishing, Inc