JavaScript listbox with ID(int) column

Hi Experts.

Do you know if it is possible to do this:

///  

[textbox]   ->  [listbox] (height 5 rows, width any)

///

by default (nothing entered) listbox should look like this:

////

[  |              ]    ||
[  |              ]    ||
[  |              ] (slider)
[  |              ]    ||
[  |              ]    ||

////

when something is added to [textbox], lets say "example", on pressing "->", this will happen to [listbox]

////

[exapmple]   ->  [1 |example   ]    ||
                         [   |               ]    ||
                         [   |               ] (slider)
                         [   |               ]    ||
                         [   |               ]    ||

/////

the same if another value is submitted, say "example 2", on pressing "->", this will happen to [listbox]

/////

[exapmple2]   ->  [1 |example   ]    ||
                           [2 |example2 ]    ||
                           [   |               ] (slider)
                           [   |               ]    ||
                           [   |               ]    ||

////

and so on... The tricky part is that "[1|" is a separate column in a listbox.

Is this possible using JavaScript?

Thank you in advance :)
andysysAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ysreCommented:
So you basically want a select-box with 5 empty option lines and fill it up lateron?
That's doable (see new Option (..) in google).

On the two tabbed option lines.. Sorry, no go.. At least not if you are shooting for a browser-independent, low cost solution.
I played around with a fixed font (eg. system), em-width definition for the select box and adding spaces before the number and |, but a) this only works in IE (mozilla needs some stuff before the spaces to print them -.-) and b) it looks really ugly.

The only way to do stuff like this is faking a select box by creating a whole new widget as can be seen here http://www.activewidgets.com/javascript.forum.926.2/introduction-to-javascript.html (the grid library can be your starting point here).

Good luck,
Ys


0
pashikCommented:
Here is example.
Hope it will help u.
it takes ready text in select element and adds number to it

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title> New Document </title>
</head>
<body>
<select name="sel" id="sel">
<option value="aaaaa">aaaaa</option>
<option value="bbbbb">bbbbb</option>
<option value="ccccc">ccccc</option>
<option value="ddddd">ddddd</option>
</select>
<script language="JavaScript">
<!--
var obj = document.getElementById("sel");
for(var i=0;i<obj.options.length;i++)
{
  //to get number of spaces before | sign
  if(i+1<10) str = "  |";
  if(i+1<99 && i+1>=10) str = " |";
  if(i+1<999 && i+1>=100) str = "|";
  obj.options[i].text = (i+1) + str + obj.options[i].text;
}
//-->
</script>
</body>
</html>
0
nabsolCommented:
Hi
I think this is exactly what you want. This example will take text from text box and if you click on ---> button; it will add an option to list box with current index. :)

JUST LIKE THIS:
                           [1 |example   ]    ||
                           [2 |example2 ]    ||
                           [   |               ] (slider)
                           [   |               ]    ||
                           [   |               ]    ||
Check this code. Working perfectly.


<html>
<head>
<title> New Document </title>
<script language="JavaScript">
<!--
function addInList()
{
 useform = document.myform;  // get form
 
 var myTextbox = document.getElementById("tb");      //text box
 if (myTextbox.value != "")             // check value of text box
 {
   var index = useform.listb.options.length;     //get last index value of list box
   var valueToAdd = index + 1 + " | " + myTextbox.value;    // adding 1 in index
   useform.listb.options[index] = new Option(valueToAdd,index);      // add option if there is some value
   myTextbox.value = "";          //empty text box
 }
 else
 {
   alert("Enter Value in Text Box")
 }
}

//-->
</script>
</head>

<body>
<form name="myform">
<input type="textbox" id="tb" name="T1" size="20">
<input type="button" onClick="addInList()" value="--->">
<select id="listb" multiple size="5">
</select>
</form>
</body>
</html>


If need something else; Let me know.

By Nab
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
andysysAuthor Commented:
Thank you Experts. That is awesome things you can do!!! I have no other option in this case, but to split points.

ysre said the right thing, as "|" had to be the real column and nabsol gave the most perfect code to my needs (I cannot really implement AJAX technologies, as I don't know how)

nabsol, ("If need something else; Let me know.") , could you check on this
http://www.experts-exchange.com/Web/Web_Languages/JavaScript/Q_21806016.html
, as it is hell. And the only one that can survive in hell is a hero?
0
ysreCommented:
To the other two answerers ;)
That's what I did in my tryout locally.. Only I did it with log / ln10 and stuff.
Problem is: It's still not a two tabbed listbox like he wanted -.-
And in IE you need to have some visible character before the spaces that should indent so it's not even a crossbrowser solution.

Try your stuff out before advising :)

Ys
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Languages and Standards

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.