...

View Full Version : Help With Simple Dropdown Box Array



mossimo
09-29-2003, 12:27 PM
Hello:

I have a simple dropdown box like this:

<select name="border">
<option value="0">0</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="">Blank</option>
</select>

In fact i have lots of them and to same space I want to use arrays to generate them automaticly.

I made this but it dosn't buil a dropdown or seprate Value/Text fields.

<script language="JavaScript">
var border = new Array(10);
for(var i=0; i < border.length; i++ ){
border[i]=i + 0;
document.write(border[i] + "<br>");
}
</script>

Anyone help?
Thanks
mossimo

glenngv
09-29-2003, 01:27 PM
do you mean this?


function buildSelect(name,max){
var s = '<select name="'+name+'">\n';
for (var i=0;i<max;i++) s+='<option value="'+i+'">'+i+'</option>\n';
s+='<option value="">Blank</option>\n';
s+='</select>';
document.write(s);
}

...

<body>
<form>
<script type="text/javascript">buildSelect('border',9)</script>
...
<script type="text/javascript">buildSelect('border2',9)</script>
...
<script type="text/javascript">buildSelect('border3',9)</script>
</form>

Vincent Puglia
09-29-2003, 03:05 PM
Hi mossimo,

Or you could modify the code here:

http://members.aol.com/grassblad/cascade3.html

Vinny

mossimo
09-29-2003, 07:10 PM
Thanks glenngv

Thats exactly what I was thinking works great.

One more thing if you don't mind

What's the correct way to add:
<select name="border" style="width: 50px" onChange="updateStyle()">

to:

var s = '<select name="'+value+'">\n';


Cheers
mossimo

glenngv
09-29-2003, 10:01 PM
var s = '<select name="'+value+'" style="width: 50px" onChange="updateStyle()">\n';

mossimo
10-02-2003, 08:05 PM
Thanks Again



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum