/    Sign up×
Community /Pin to ProfileBookmark

display array in a list box

Hi,

How do i display the items which are in my array, in a list box?

Jo

to post a comment
JavaScript

6 Comments(s)

Copy linkTweet thisAlerts:
@vwphillipsJan 16.2008 — [CODE]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>
<title></title>
<script language="JavaScript" type="text/javascript">
<!--
var Ary=[];
Ary[0]=['Tom','1'];
Ary[1]=['Dick','10'];
Ary[2]=['Harry','111'];

function zxcPopulate(zxcid,zxcary){
var zxcsel=document.getElementById(zxcid);
zxcsel.options.length=0;
for (var zxc0=0;zxc0<zxcary.length;zxc0++){
zxcsel.options[zxc0]=new Option(zxcary[zxc0][0],zxcary[zxc0][1],true,true);
}
zxcsel.selectedIndex=0;
}

//-->
</script>
</head>

<body>
<input type="button" name="" value="Populate" onclick="zxcPopulate('tst',Ary);">
<select id="tst" style="width:100px;" ></select>
</body>

</html>[/CODE]
Copy linkTweet thisAlerts:
@KorJan 16.2008 — <i>
</i>&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&gt;
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Untitled Document&lt;/title&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"&gt;
&lt;meta http-equiv="Content-Style-Type" content="text/css"&gt;
&lt;meta http-equiv="Content-Script-Type" content="text/javascript"&gt;
&lt;script type="text/javascript"&gt;
function populateList(){
var Arr=['apple','banana','orange']
var sel=document.getElementById('mySel'), i=0, a, o;
while(a=Arr[i++]){
o=document.createElement('option');
o.value=a;
o.appendChild(document.createTextNode(a))
sel.appendChild(o)
}
}
onload=populateList;
&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;select id="mySel"&gt;&lt;/select&gt;
&lt;/body&gt;
&lt;/html&gt;
Copy linkTweet thisAlerts:
@shd05017authorJan 16.2008 — thanks, but thats not quite what i meant. sorry its probably the way i worded it. i dont have the items of my array, they are created by words entered into a text box. so everytime they enter somethin new i need it to be displayed in a select box, not a list box. sorry, my mistake. hope you guys can still help me

thanks

Jo
Copy linkTweet thisAlerts:
@KorJan 16.2008 — <i>
</i>&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&gt;
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Untitled Document&lt;/title&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"&gt;
&lt;meta http-equiv="Content-Style-Type" content="text/css"&gt;
&lt;meta http-equiv="Content-Script-Type" content="text/javascript"&gt;
&lt;script type="text/javascript"&gt;
function populateList(f){
var o=document.createElement('option');
o.value=f['txt'].value;
o.appendChild(document.createTextNode(f['txt'].value))
f['mySel'].appendChild(o);
}
&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;form&gt;
&lt;input type="text" name="txt"&gt;&lt;input type="button" onclick="populateList(this.form)" value="Add to List"&gt;
&lt;br&gt;
&lt;select name="mySel"&gt;&lt;/select&gt;
&lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;
Copy linkTweet thisAlerts:
@shd05017authorJan 16.2008 — thanks. that will help me out alot.
Copy linkTweet thisAlerts:
@vwphillipsJan 16.2008 — [CODE]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>
<title></title>
<script language="JavaScript" type="text/javascript">
<!--

function zxcPopulate(zxcid,zxcip){
var zxcsel=document.getElementById(zxcid);
var zxcval=document.getElementById(zxcip).value;
if (zxcval.length==0) return;
for (var zxc0=0;zxc0<zxcsel.options.length;zxc0++){
if (zxcsel.options[zxc0].text==zxcval) return;
}
zxcsel.options[zxcsel.options.length]=new Option(zxcval,'',true,true);
zxcsel.selectedIndex=0;
}

//-->
</script>
</head>

<body>
<input id="ip"><input type="button" name="" value="Enter" onclick="zxcPopulate('tst','ip');">
<select id="tst" style="width:100px;" ></select>
</body>[/CODE]
×

Success!

Help @shd05017 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...