Hi,
I have constructed a clickable list of words which are added to a select box. I then have buttons to move the added elements up or down in the list.
The code below seems to work fine for the first change (UP only) but after that the last element in the list disappears :(
I have no idea why this is happening so could anyone offer a solution or a better method of doing the above task? Thanks in advance - <html>
-
<head>
-
<script type="text/javascript">
-
-
function moveText(name, id)
-
{
-
var selected_box = document.getElementById("textarea_two");
-
var new_option = new Option(name, id);
-
selected_box.options[selected_box.length] = new_option;
-
}
-
-
-
function moveup(){
-
-
var y=document.getElementById("textarea_two").selectedIndex
-
var x=document.getElementById("textarea_two").options
-
-
if (y>0){
-
var selected = x[y];
-
var dest = x[y-1];
-
-
//swap option elements
-
x[y-1] = selected;
-
x[y] = dest;
-
-
//reset variables if necessary ?
-
x = null;
-
y = null;
-
selected = null;
-
dest = null;
-
}
-
}
-
</script>
-
</head>
-
-
<body>
-
<table>
-
<tr>
-
<td id="textarea_one">
-
<li id= "1" title="text one" ondblclick="moveText(this.title, this.id)">text one</li>
-
<li id= "2" title="text two" ondblclick="moveText(this.title, this.id)">text two</li>
-
<li id= "3" title="text three" ondblclick="moveText(this.title, this.id)">text three</li>
-
</td>
-
</tr>
-
</table>
-
-
<br>
-
<select id="textarea_two" style="width:150px;" size="7"></select>
-
<br>
-
-
Move selected: <br>
-
><span onclick="moveup()">UP</span><br>
-
><span onclick="movedown()">DOWN</span>
-
-
-
</body>
-
</html>
1 3039
I've made a work around for this problem. I used a string to store both the previous and next values of each option element that is being changed so as to avoid loosing the data, which is what was happening in the above code.
Hope this might be useful to somebody. If anyone knows a simpler way of doing this please let me know! Cheers Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Hal Vaughan |
last post by:
I have a sample script from a book ("Beginning JavaScript" by Paul Wilton)
that removes or adds a choice to a <SELECT> element. The <FORM> is form1
and the <SELECT> is theDay. The example uses these lines (full text is
below):
if (document.form1.theDay.options.text != "Wednesday) {
var days = document.form1.theDay;
days.options.text = days.options.text;
<snip>
var option - new Option("Wednesday", 2);
|
by: F. Da Costa |
last post by:
Hi,
Does anybody know why IE5+ does *not* honour array objects (like a table)
across a session?
Example:
Frame A contains a var tableVar which is set via form Frame B (on init)
using top.A.tableVar = document.getElementById("someTable");
As long as Frame B is *not* 'refreshed/ reloaded' witk another page the
|
by: Paolo Pignatelli |
last post by:
I am trying to get an output/file like this (below) in an XML file
(MyXmlFile.xml) (which I will use for a slide show)
--
<gallery timer="3" order="sequential" fadetime="2" looping="yes" xpos="0"
ypos="0">
<image path="images2/Test1.jpg" />
|
by: dtwalter |
last post by:
Is it possible to ORDER BY a SubSelect? I don't see why it wouldn't
be, but I'm having some trouble. Hopefully it's just a simple error in
syntax and somebody can tell me. Here's what I'm trying to do...
I've got two tables:
Table1:
TestData Filename
Bird FileB
Blue FileA
Circle FileC
|
by: shankwheat |
last post by:
I've been using this little script to change the <a href=""></a> value
of a link which works well.
<script language="javascript" type="text/javascript">
function ordering(sorder)
{
var link = document.getElementById("mylink").href =
"http://www.mysite.com?Option="+sorder;
}
</script>
| |
by: Jason |
last post by:
Hi all,
I know how to do this the hard way, but I suspect that there's an
easier option.
I'm creating a program that requires a series of 4 or 6 select menus.
Something like this:
<select name="1">
<option value="a">A</option>
|
by: groups2 |
last post by:
I have a form with a dropdown (select) menu a text input field and
some hidden values, along with an input botton that triggers an ajax
function that submits the form.
If the button is after the select statement, the chosen value of the
selection of the dropdown is posted. But if the button is before the
select statement, everything in the form is posted but the value of
the selection
Why would the select box be left out of the post ?
|
by: paul |
last post by:
I have a JS function to change the width of a <divthat works great
in Firefox, but not at all in IE7. In IE an error message occurs:
Line: 92
Char: 5
Error: Invalid Argument
Code: 0
Firefox reports no errors in the Error Console, or Firebug, and the
<divis resized correctly. Here is the function:
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |