Welcome to WebmasterWorld Guest from

Forum Moderators: open

Message Too Old, No Replies

var choice



5:45 pm on Mar 18, 2008 (gmt 0)

10+ Year Member

when declaring a var can it have a space or + sign, if so how would you go about constructing this.


6:36 pm on Mar 18, 2008 (gmt 0)

WebmasterWorld Senior Member fotiman is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month

No, JavaScript vars can not have spaces or plus signs in their names.


6:44 pm on Mar 18, 2008 (gmt 0)

10+ Year Member

great if only i new this 9 hours ago lol.
i have a script that takes a value from box1 and in javascript the var becomes that name hence the question with spaces/+sign other than an underscore do you have any ideas?.


7:07 pm on Mar 18, 2008 (gmt 0)

5+ Year Member

Any number of ways to go. You're looking for a lookup table. That's sort of to what the 'object' design lends itself.

If it's more complicated than that, you could show here exactly what you're trying to do.


8:47 pm on Mar 18, 2008 (gmt 0)

10+ Year Member

this is the script:
var Alfa_Romeo = new Array("('Select model','',true,true)","('146')","('147')","('156')","('159')","('166')","('Brera')","('GT')","('GTV')","('Spider')","('Any')");var Aston_Martin = new Array("('Select model','',true,true)","('DB7')","('DB9')","('Vanquish')","('Vantage')","('Virage')","('Any')");var Audi = new Array("('Select model','',true,true)","('100')","('80')","('A2')","('A3')","('A4')","('A4 Avant')","('A4 Cabriolet')","('A6')","('A6 Avant')","('A8')","('Cabriolet')","('Convertible')","('Coupe')","('Q7')","('S3')","('S4')","('S8')","('TT Coupe')","('Any')");
function populatemodel(inForm,selected) {
var selectedArray = eval(selected);

while (selectedArray.length < inForm.model.options.length) {
inForm.model.options[(inForm.model.options.length - 1)] = null;
for (var i=0; i < selectedArray.length; i++) {
eval("inForm.model.options[i]=" + "new Option" + selectedArray[i]);

if (inForm.make.options[0].value == '') {
inForm.make.options[0]= null;
if ( navigator.appName == 'Netscape') {
if (parseInt(navigator.appVersion) < 4) {
else {
if (navigator.platform == 'Win32' navigator.platform == 'Win16') {

// End -->
i want the alfa romeo to be alfa+romeo in the url bar after submission and not alfa_romeo as it is now


8:45 am on Mar 19, 2008 (gmt 0)

5+ Year Member

Well, it's nearly impossible to know what you intend from the code you have listed.

Put this in your browser's location bar and hit the Enter key and you may get an idea.

javascript:alert("Alfa_Romeo".replace("_", "+"));

Edit: left out closing paren.

[edited by: MarkFilipak at 8:47 am (utc) on Mar. 19, 2008]


Featured Threads

Hot Threads This Week

Hot Threads This Month