/    Sign up×
Community /Pin to ProfileBookmark

delete the options in a select box ?

How to delete the options in a select box ?

I have three combo boxes, when i select an option in a combo , the values in the other 2 combo boxes must change ( fetched from an array).

I used to the remove method as : in IE – selectElement.options.remove(i)
and in Mozilla as
selectElement.options[i].remove;

but the values still appear in the combo’s.

plz help me !

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@Warren86Mar 23.2005 — Maybe you will find this to be a useful guide.

<HTML>

<Head>

<Script Language=JavaScript>

Level1 = new Array("Apparel","Books")

Apparel = new Array("Men","Women")
Books = new Array("Biography","Fiction","Nonfiction")

Men = new Array("Shirts","Ties","Belts")
Women = new Array("Blouses","Skirts","Scarves")

Biography = new Array("Contemporay","Historical","Other")
Fiction = new Array("Science","Romance")
Nonfiction = new Array("How-To","Travel","Cookbooks")

function fillSelect(isValue,isNext){

isNext.style.display = "";
isNext.length = 1;
curr = eval(isValue);
for (each in curr)
{
isData = new Option(curr[each],curr[each]);
isNext.add(isData,isNext.options.length);
}
}

function getValue(isValue){

alert(isValue);
}


</Script>

</Head>

<Body>

<center>

<h4>Dependent Select List, within a form</h4>

<Form name='Categories'>

<Select name='List1' onChange="fillSelect(this.value,Categories.List2)">

<option selected>Make a selection</option>

</Select>

&nbsp

<Select name='List2' onChange="fillSelect(this.value,Categories.List3)">

<option selected>Make a selection</option>

</Select>

&nbsp

<Select name='List3' onChange="getValue(this.value)">

<option selected >Make a selection</option>

</Select>

</Form>

</center>

<Script>

fillSelect('Level1',Categories.List1)

Categories.List2.style.display = "none";

Categories.List3.style.display = "none";

</Script>

</Body>

</HTML>
Copy linkTweet thisAlerts:
@FangMar 23.2005 — Deletes selected:
&lt;form action="#" name="form1"&gt;
&lt;select name="select1" onchange="document.forms['form1'].select1.options[selectedIndex]=null;"&gt;
&lt;option value="1"&gt;a&lt;/option&gt;
&lt;option value="2"&gt;b&lt;/option&gt;
&lt;option value="3"&gt;c&lt;/option&gt;
&lt;/select&gt;
&lt;/form&gt;

To delete them all use:
document.forms['form1'].select1.length=null
Copy linkTweet thisAlerts:
@drahulauthorMar 24.2005 — [i]Originally posted by Fang [/i]

[B]Deletes selected:

&lt;form action="#" name="form1"&gt;
&lt;select name="select1" onchange="document.forms['form1'].select1.options[selectedIndex]=null;"&gt;
&lt;option value="1"&gt;a&lt;/option&gt;
&lt;option value="2"&gt;b&lt;/option&gt;
&lt;option value="3"&gt;c&lt;/option&gt;
&lt;/select&gt;
&lt;/form&gt;

To delete them all use:
document.forms['form1'].select1.length=null [/B][/QUOTE]


Thanks Fang !

You gave me the perfect solution !

Thanks once again !!
×

Success!

Help @drahul 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 5.18,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

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

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...