Welcome to WebmasterWorld Guest from 54.198.183.217

Forum Moderators: open

Message Too Old, No Replies

var choice

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

Preferred Member from GB 

10+ Year Member

joined:Jan 26, 2004
posts:636
votes: 0


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)

Senior Member from US 

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

joined:Oct 17, 2005
posts:4988
votes: 12


No, JavaScript vars can not have spaces or plus signs in their names.
6:44 pm on Mar 18, 2008 (gmt 0)

Preferred Member from GB 

10+ Year Member

joined:Jan 26, 2004
posts:636
votes: 0


great if only i new this 9 hours ago lol.
right
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)

Junior Member

5+ Year Member

joined:Feb 14, 2008
posts:144
votes: 0


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)

Preferred Member from GB 

10+ Year Member

joined:Jan 26, 2004
posts:636
votes: 0


this is the script:
<HEAD>
<SCRIPT LANGUAGE="JavaScript">
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) {
window.history.go(0);
}
else {
if (navigator.platform == 'Win32' navigator.platform == 'Win16') {
window.history.go(0);
}
}
}
}
}

// End -->
</script>
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)

Full Member

5+ Year Member

joined:Mar 4, 2008
posts: 210
votes: 0


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]