By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,220 Members | 1,798 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,220 IT Pros & Developers. It's quick & easy.

Remove an item from a select box

P: n/a
Rob

Hi,
I've got a small javascript problem and I'm kinda stuck. I'm using
classic ASP. I have a select box which is populated by a database query
and there is a buttom that when clicked it will move the selected item
from the first select box and move it to another select box:

document.form2.list.options[document.form2.list.options.length] = new
Option(count + 1 + ". " + name,company);

Then I want to remove it from the first select box:
document.form1.companies.options[document.form1.companies.selectedIndex]
.text = "";

But that just leaves an empty spot. I need to remove that spot
altogether and move all the other items up by one.
This is what I have:
for (i=document.form1.companies.options.length-1; i>0;
i--){document.form1.companies.options[document.form1.companies.selectedI
ndex].value = i;
}

But this doesn't work.
Anyone have any ideas?

Thanks

Rob

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 23 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Rob wrote:
Hi,
I've got a small javascript problem and I'm kinda stuck. I'm using
classic ASP. I have a select box which is populated by a database query
and there is a buttom that when clicked it will move the selected item
from the first select box and move it to another select box:

<snip>

Really Nice Code:

http://www.mattkruse.com/javascript/selectbox/

Mike
Jul 23 '05 #2

P: n/a
Rob
I know...I'm not big on Javascript.
Thanks for the code.

Rob

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 23 '05 #3

P: n/a
Rob wrote:
Hi,
I've got a small javascript problem and I'm kinda stuck. I'm using
classic ASP. I have a select box which is populated by a database query and there is a buttom that when clicked it will move the selected item from the first select box and move it to another select box:

document.form2.list.options[document.form2.list.options.length] = new
Option(count + 1 + ". " + name,company);

Then I want to remove it from the first select box:
document.form1.companies.options[document.form1.companies.selectedIndex] text = "";

But that just leaves an empty spot. I need to remove that spot
altogether and move all the other items up by one.
This is what I have:
for (i=document.form1.companies.options.length-1; i>0;
i--){document.form1.companies.options[document.form1.companies.selectedI ndex].value = i;
}

But this doesn't work.
Anyone have any ideas?

Thanks

Rob

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!


<html>
<head>
<script type="text/javascript">

function delSelectedOpt(sel_id)
{
var o,
os,
len,
i = 0,
selobj = document.getElementById(sel_id);
if (selobj && (os = selobj.options))
{
while (o = os[i++])
if (o.selected)
{
for (len = os.length; i < len; ++i)
os[i - 1] = new Option(os[i].text, os[i].value);
os[--len] = null;
}
}
}

</script>
</head>
<body>
<form>
<select id="sss" size="8">
<option value="0">Option 0</option>
<option value="1">Option 1</option>
<option value="2">Option 2</option>
<option value="3">Option 3</option>
<option value="4">Option 4</option>
<option value="5">Option 5</option>
<option value="6">Option 6</option>
<option value="7">Option 7</option>
</select>
<input type="button"
value="delete selected"
onclick="delSelectedOpt('sss')" />
</form>
</body>
</html>

Jul 23 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.