/    Sign up×
Community /Pin to ProfileBookmark

Looping and Removing all options

Hi

Is this correct to clear select items?

function(sel){
var selected = sel.options[w].text;
var name=sel.name;

(i=1; i<sel.length=0,i++){
sel.options.length=0;}

if(var name=”test”){
for (i=0;i< test;i++)
.
.
.
}

<select name=”test” id=”test” onchange=”updateOrder(this);”>

<option>0</option>
<option>1</option>

<td bgcolor=”#FFE9BB” class=”borderBR”><select name=”example” size=”4″ multiple=”multiple” id=”example”> <option>0</option>

to post a comment
JavaScript

11 Comments(s)

Copy linkTweet thisAlerts:
@KravvitzAug 26.2006 — To remove the options all you need is this:
sel.options.length=0;
http://www.quirksmode.org/js/options.html
Copy linkTweet thisAlerts:
@gregc_authorAug 26.2006 — But what I want to happen is to create a loop whereby existing options are cleared, and the new one entered in its place. Thereby giving the user a choice.
Copy linkTweet thisAlerts:
@CrazyMerlinAug 26.2006 — (i=1; i<sel.length=0,i++){

...is meaningless

you are iterating wrongly, you are setting a value upon comparison, and your code is written completely wrong

what is it you want to do exactly.

I'm not flaming you, just pointing out that your code is really bad, sorry
Copy linkTweet thisAlerts:
@gregc_authorAug 26.2006 — I'll leave it there then. Thanks for your help.
Copy linkTweet thisAlerts:
@CrazyMerlinAug 26.2006 — why be defeated so early on?

just explain what you want and I'll help.
Copy linkTweet thisAlerts:
@gregc_authorAug 26.2006 — Writing from select1 to select2. What I trying to make happen is each time the user makes a select1 I want it to overwrite/delete the existing select and insert the new one. At the moment, I have one happening after the other.
Copy linkTweet thisAlerts:
@gregc_authorAug 26.2006 — clarification:I want it to overwrite/delete the existing select2 and insert the new one. At the moment, I have one happening after the other.
Copy linkTweet thisAlerts:
@CrazyMerlinAug 26.2006 — ok, you have 2 select boxes...and when the use selects an option in box 1 you want what to happen in box 1, and what to happen in box 2?
Copy linkTweet thisAlerts:
@gregc_authorAug 26.2006 — For example, I select A from select1 and it prints A in select2. I've got that happening okay. But if I select B from select1 I want it to print over A in select2. At the moment it prints underneath.
Copy linkTweet thisAlerts:
@CrazyMerlinAug 26.2006 — ok, when you select the option in select1 do you ALWAYS want it to overwrite that first option in select2?
Copy linkTweet thisAlerts:
@CrazyMerlinAug 26.2006 — nice! thanks for just leaving while I was trying to help you.

ok just setting the select2 option to select1 selected option is simple

document.select2.options[0] = document.select1[document.select1.selectedIndex]

blah!
×

Success!

Help @gregc_ 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.19,
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,
)...