/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] noob javascript problem

Hi everyone
I just started to learn Javascript and i am running into a problem i just cant figure out how to fix. Just to set up the situation i have a combo box with different options in it and i created a button to remove an option if i desire. When the button is pressed 2 options are removed and it is never the selected option…. if any of you pros can spare a min to look at this i would greatly appreciate it. Thanks in advance Chris Osburn

[CODE]
function RemoveListItem(RemoveItemName){
var oListOutPut = document.getElementById(‘ListOutPut’);
var intListLength = oListOutPut.options.length;
for (var i=0; i <= intListLength; i++){
if (oListOutPut.options[i].value = RemoveItemName){
oListOutPut.options[i] = null;

}
}
}
[/CODE]

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@ZeroKilledOct 29.2008 — try this code:
<i>
</i>function removeOption(){
var oListOutPut = document.getElementById('ListOutPut');
oListOutPut.remove(oListOutPut.selectedIndex);
}
Copy linkTweet thisAlerts:
@MrChrisOsburnauthorOct 29.2008 — Dude you are the man it worked great and now i dont have to worry about another error i was getting. If i could give you a star i would thanks again Chris Osburn
Copy linkTweet thisAlerts:
@ZeroKilledOct 29.2008 — sorry for not explaining a bit about your code. at a glance, in the line [b]if (oListOutPut.options[i].value = RemoveItemName){[/b] what you really doing is assigning a value to the property [b]value[/b] instead of camparing the option's value with the variable. so, you have to use the comparison ==
×

Success!

Help @MrChrisOsburn 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.16,
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,
)...