How do I change contents of pulldown?

N

nsteele84

Hi

I need to clear the contents of a pulldown and then load new contents
into it. Is this possible in Javascript? If so how?

Thanks

Nick Steele
 
M

Mick White

Hi

I need to clear the contents of a pulldown and then load new contents
into it. Is this possible in Javascript? If so how?

Yes, it is, but in what format are the replacement items?


function clearMenu(menu,keepHeader){
menu.length=keepHeader?1:0;
}

function replaceMenu(menu,array,keepHeader){
clearMenu(menu,keepHeader);
a=array.length;
for(i=0;i<a;i++){
menu.options[menu.length]=new Option(array,array);
}
}
Consider a select menu named "foo"

<HTMLelement
onclick="replaceMenu(document.forms[0].foo,['select a number',1,2,3,4])">

Mick
 
G

Grunken

Hi

I need to clear the contents of a pulldown and then load new contents
into it. Is this possible in Javascript? If so how?

Thanks

Nick Steele

Yes it's possible :eek:)

something like this you'r looking for ?


<script type="text/javascript">
newOpt = []; //array with new values
newOpt[0] = "newVal1"
newOpt[1] = "newVal2"
newOpt[2] = "newVal3"
newOpt[3] = "newVal4"


function changeOpt(){
opt = document.frm.whee.options
for(var i=0;i<newOpt.length;i++){
opt=new Option(newOpt,newOpt);
}
for(i=i;i<opt.length;i++)
opt=null
}
</script>

<form name="frm">
<select name="whee">
<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>
</select>
</form>

<a href="#" onclick="changeOpt();return false">Newvalue</a>

Best Regards

Nick
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,434
Messages
2,571,691
Members
48,796
Latest member
Greg L.

Latest Threads

Top