/    Sign up×
Community /Pin to ProfileBookmark

removeMe() Function does not work

RemoveME function removes more than one item when populating the select fields from the user input feilds instead of the select fields.

[code]

<HEAD>

<SCRIPT LANGUAGE=”JavaScript”>

<!– Begin
function moveOver()
{
var boxLength = document.choiceForm.choiceBox.length;
var selectedItem = document.choiceForm.available.selectedIndex;
var selectedText = document.choiceForm.available.options[selectedItem].text;
var selectedValue = document.choiceForm.available.options[selectedItem].value;
var i;
var isNew = true;
if (boxLength != 0) {
for (i = 0; i < boxLength; i++) {
thisitem = document.choiceForm.choiceBox.options[i].text;
if (thisitem == selectedText) {
isNew = false;
break;
}
}
}
if (isNew) {
newoption = new Option(selectedText, selectedValue, false, false);
document.choiceForm.choiceBox.options[boxLength] = newoption;
}
document.choiceForm.available.selectedIndex=-1;
}
function removeMe() {
var boxLength = document.choiceForm.choiceBox.length;
arrSelected = new Array();
var count = 0;
for (i = 0; i < boxLength; i++) {
if (document.choiceForm.choiceBox.options[i].selected) {
arrSelected[count] = document.choiceForm.choiceBox.options[i].value;
}
count++;
}
var x;
for (i = 0; i < boxLength; i++) {
for (x = 0; x < arrSelected.length; x++) {
if (document.choiceForm.choiceBox.options[i].value == arrSelected[x]) {
document.choiceForm.choiceBox.options[i] = null;
}
}
boxLength = document.choiceForm.choiceBox.length;
}
}

function reshow() {

whatTo = document.choiceForm.elements.choiceBox;
for (var i = whatTo.length;i > 0;i–)
whatTo.options[0] = null;
if (document.choiceForm.manual4.value != ”) {
showLink();
}
else {}
}

function showLink() {

opt(document.choiceForm.manual0.value);
opt(document.choiceForm.manual1.value);
opt(document.choiceForm.manual2.value);
opt(document.choiceForm.manual3.value);
}

function opt(text) {
var optionName = new Option(text)
var length = whatTo.length;
whatTo.options[length] = optionName;
}

// End –>
</script>

</HEAD>

<BODY>

<center>
<form name=”choiceForm”>

<table border=0>
<tr>
<td valign=”top” width=175>
Available Content:
<br>
<select name=”available” size=10 onchange=”moveOver();”>
<option value=1>Company News
<option value=2>Industry News
<option value=3>Product Updates
</select>
</td>
<td valign=”top”>
Your Choices:
<br>
<select name=”choiceBox” style=”width:150;” size=”10″ onchange=”removeMe();”>
</select>
</td>
</tr>
<tr>
<td colspan=2 height=10>

</td>
</tr>
</table>
<input type=”button” value=”Get Selected Values” onclick=”reshow();”>
<input type=”text” value=”Company News” name=”manual0″>
<input type=”text” value=”Industry News” name=”manual1″>
<input type=”text” value=”Product Updates” name=”manual2″>
<input type=”text” value=”Help Me” name=”manual3″>
<input type=”hidden” value=w34 name=”manual4″>
</form>
</center>

[/code]

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@skriptorMar 12.2007 — Try this:

for (i = 0; i < boxLength; i++) {

if (document.choiceForm.choiceBox.options[i].selected) {

arrSelected[count] = document.choiceForm.choiceBox.options[i].value;

count++;

}

}



skriptor
Copy linkTweet thisAlerts:
@pentaceauthorMar 12.2007 — Still does the exact thing.
×

Success!

Help @pentace 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.21,
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,
)...