spacey
01-28-2005, 10:24 AM
Hello All,
Hopefully somebody here can offer a little guidance.
What i’m trying to achieve:
I'd like to be able to use a combo box to change lots of values on my webpage. Due to the large amount of items to update on the page I was going to store the items in a JavaScript hash.
Then use an “onchange” routine to find the selected item in the combo and just do a simple
for (var x in SELECTEDHASHNAME). Unfortunately due to the combo box storing the selection as a string I can’t simply refer to it in the above statement by name. I’m guessing it has to be converted from string to an object reference. Although I could be way of the mark with this thought?
So back to the question...
Can you use a combo box to refer to the name of a hash that you can then interrogate with a "for x in hash" stile statement?
Hopefully somebody here will understand my ramblings and have a suggestion.
Thanks to one and all for any help they maybe able to offer.
Gareth
Ps. I have attached some sample code that shows what I want to do. If you substitute the “i" for “Mon” it will work.
Likewise I’d want to be able to substitute the Mon[s] for i[s] to make it truly dynamic.
<html>
<head>
<title>Test</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script>
function changedata()
{
var Sun = new Object();
var Mon = new Object();
var i;
Sun.User ='UserA';
Mon.User ='UserB';
Mon.Price ='£5';
pp=document.all["dayid"];
for(m=0;m<pp.options.length;m++)
{
if(pp.options[m].selected==true)
{
i=pp.options[m].value;
alert(i);
for (var s in i) //replace i with Var Mon and it works ...pesky thing grr
{
alert('Key=' + s);
document.all[s].innerText = Mon[s] ; //would also need to change Mon to 'i' here
}
break;
}
}
}
</script>
</head>
<body bgcolor="#FFFFFF" text="#000000">
<form name="form1" method="post" action="">
<select id = "dayid" name="days" onchange="changedata();">
<option value="Sun" selected>Sun</option>
<option value="Mon">Mon</option>
<option value="Tue">Tue</option>
<option value="Wed">Wed</option>
<option value="Thu">Thu</option>
<option value="Fri">Fri</option>
<option value="Sat">Sat</option>
</select>
<p id=User>Select an option from the combo box above</p>
<p id=Price>Price</p>
</form>
</body>
</html>
Hopefully somebody here can offer a little guidance.
What i’m trying to achieve:
I'd like to be able to use a combo box to change lots of values on my webpage. Due to the large amount of items to update on the page I was going to store the items in a JavaScript hash.
Then use an “onchange” routine to find the selected item in the combo and just do a simple
for (var x in SELECTEDHASHNAME). Unfortunately due to the combo box storing the selection as a string I can’t simply refer to it in the above statement by name. I’m guessing it has to be converted from string to an object reference. Although I could be way of the mark with this thought?
So back to the question...
Can you use a combo box to refer to the name of a hash that you can then interrogate with a "for x in hash" stile statement?
Hopefully somebody here will understand my ramblings and have a suggestion.
Thanks to one and all for any help they maybe able to offer.
Gareth
Ps. I have attached some sample code that shows what I want to do. If you substitute the “i" for “Mon” it will work.
Likewise I’d want to be able to substitute the Mon[s] for i[s] to make it truly dynamic.
<html>
<head>
<title>Test</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script>
function changedata()
{
var Sun = new Object();
var Mon = new Object();
var i;
Sun.User ='UserA';
Mon.User ='UserB';
Mon.Price ='£5';
pp=document.all["dayid"];
for(m=0;m<pp.options.length;m++)
{
if(pp.options[m].selected==true)
{
i=pp.options[m].value;
alert(i);
for (var s in i) //replace i with Var Mon and it works ...pesky thing grr
{
alert('Key=' + s);
document.all[s].innerText = Mon[s] ; //would also need to change Mon to 'i' here
}
break;
}
}
}
</script>
</head>
<body bgcolor="#FFFFFF" text="#000000">
<form name="form1" method="post" action="">
<select id = "dayid" name="days" onchange="changedata();">
<option value="Sun" selected>Sun</option>
<option value="Mon">Mon</option>
<option value="Tue">Tue</option>
<option value="Wed">Wed</option>
<option value="Thu">Thu</option>
<option value="Fri">Fri</option>
<option value="Sat">Sat</option>
</select>
<p id=User>Select an option from the combo box above</p>
<p id=Price>Price</p>
</form>
</body>
</html>