473,394 Members | 2,090 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Processing delimited list then adding to listbox in java script

I haven't worked with java script much, I know how to do this server side by
constant post backs to the server on a webform, but it seems like i should
be able to do this client side also...

What happens is a modal dialog recieves a listing of users in a semi-colon
delimited list so its like this

user_1;user_2;user3;user_4;

what I need to do is split this up in javascript and place each user into a
listbox on the client side, how would i go about doing that? thanks
Nov 18 '05 #1
1 1573
Hi Brian,

From your description, you'd like to split a string into an array in
javascript code and dynamically create some items of
a html listbox according to the values in the array via javascript , yes?

As for this problem, here are my suggestions:
1. The string spliting can be done by the split() member function of the
text object, for example

var txt = "user1;user2;user3";
var array = txt.split(";");

2. And as for dynamically create option items for listbox( infact it is a
<select> html element), we can use the following code:

//modelSelect is an <select > html element

modelSelect.options.length = 0; // Clear the popup

modelSelect.options[0] = new Option("Explorer");
modelSelect.options[1] = new Option("Mustang");
modelSelect.options[2] = new Option("Probe");

And here is a web tech article discussing this:
#Focus on JavaScript --- Modifying Items in a Dropdown List
http://javascript.about.com/library/.../aa072903a.htm

In addition, here a simple demo page , you may also have a look if you feel
anything unclear:
====================================
<HTML>
<HEAD>
<title>jslistbox</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
<script language="javascript">
function setUsers()
{
var txt = document.getElementById("txtUsers").value;
var lst = document.getElementById("lstUsers");

if(txt != null && txt.length != 0)
{
var arr_users = txt.split(";");
lst.options.length = 0;

var i=0;
for(i=0;i<arr_users.length;i++)
{
lst.options[i] = new Option(arr_users[i]);
}
}
}
</script>
</HEAD>
<body>
<form id="Form1" method="post" runat="server">
<table width="100%" align="center">
<tr>
<td>
<SELECT size="5" id="lstUsers">
<OPTION></OPTION>
</SELECT>
</td>
</tr>
<tr>
<td><INPUT type="text" id="txtUsers"></td>
</tr>
<tr>
<td><INPUT id="btnSetUsers" type="button" value="Set Users"
onclick="setUsers()"></td>
</tr>
</table>
</form>
</body>
</HTML>
=============================================

Hope these help. Thanks.
Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx
Nov 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Garry | last post by:
Hi, I am new to python, hope someone can help me here: I have a MS Access exported .txt file which is tab delimited in total 20 columns, now I need to add another column of zero at the 4th column...
1
by: Anthony Liu | last post by:
I believe that topic related to Chinese processing was discussed before. I could not dig out the info I want from the mail list archive. My Python script reads some Chinese text and then split...
3
by: Brian Henry | last post by:
I have two list boxes on my form... lstCanSend and lstRecipients... well then there are two buttons add and remove between them (your basic select and pick listing) which uses java script to move...
6
by: hardik | last post by:
hi friends i am very new to java script.if anyone can help me out then i will be thankful. i am using php and mysql in my learning project and i have two list boxes,now whenever user presses...
2
by: ManningFan | last post by:
Every month I get a huge list of product codes I need to track. I have written a very detailed script to perform this task. The problem is, I copied someone else's form because I was in a rush....
6
by: Osiris | last post by:
Is the following intuitively feasible in Python: I have an array (I come from C) of identical objects, called sections. These sections have some feature, say a length, measured in mm, which is...
2
by: Ron | last post by:
so if my textbox is named textbox1 and my listbox is named ltsdisplay, for the button that would make this all happen I would just need to: ...
9
by: Ajinkya | last post by:
Hello friends ! , I am very new to java script.If anyone can help me then I will be very very thankful to his/her. I am using php and mysql in my project and I have one textarea and one...
1
by: skyson2ye | last post by:
Hi, guys: I have written a piece of code which utilizes Javascript in PHP to create a three level dynamic list box(Country, States/Province, Market). However, I have encountered a strange problem,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
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,...
0
jinu1996
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...
0
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.