Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

JavaScript listbox with ID(int) column

Posted on 2006-04-06
5
Medium Priority
?
571 Views
Last Modified: 2010-04-06
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 :)
0
Comment
Question by:andysys
5 Comments
 
LVL 4

Assisted Solution

by:ysre
ysre earned 200 total points
ID: 16396340
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
 
LVL 2

Assisted Solution

by:pashik
pashik earned 600 total points
ID: 16400458
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
 
LVL 6

Accepted Solution

by:
nabsol earned 1200 total points
ID: 16401608
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
 

Author Comment

by:andysys
ID: 16403199
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
 
LVL 4

Expert Comment

by:ysre
ID: 16404895
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

Featured Post

[Webinar] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
Without even knowing it, most of us are using web applications on a daily basis.  In fact, Gmail and Yahoo email, Twitter, Facebook, and eBay are used by most of us daily—and they are web applications. We generally confuse these web applications to…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

564 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question