Dynamic population of list box |
Dynamic population of list box |
Meena Iyer |
Mar 5 2009, 12:39 AM
Post
#1
|
Group: Members Posts: 2 Joined: 5-March 09 Member No.: 7,977 |
Hi all,
I have a list box, which has a list of values, and i also have a submit buttoon. My requirement When the user selects a value from the list box, that particular value should be populated to another list box. <html:html> <html:form action="/meena1.do" > <select multiple="multiple" name="select"> <option>apple</option> <option>mango</option> <option>orange</option> <option>grape</option> <select> <INPUT type="submit" name="Submit" value="Send the fruit name"> ....here i need another list box which would be empty when the page loads, and when the user selects , "mango", mango has to be added as a item in the second list box.. </html:form> </html:html> Can anyone help me with a sample code?? Thanks, Meena |
Darin McGrew |
Mar 5 2009, 01:37 AM
Post
#2
|
WDG Member Group: Root Admin Posts: 8,365 Joined: 4-August 06 From: Mountain View, CA Member No.: 3 |
You can use JavaScript for this kind of thing (assuming that it is enabled/available). But why can't /meena1.do use the value of the select element? Why does it need another element to have the same value?
|
Meena Iyer |
Mar 5 2009, 04:41 AM
Post
#3
|
Group: Members Posts: 2 Joined: 5-March 09 Member No.: 7,977 |
You can use JavaScript for this kind of thing (assuming that it is enabled/available). But why can't /meena1.do use the value of the select element? Why does it need another element to have the same value? Hi Darin, yeah, you're right.. am using this piece of code now.. <html> <script language="javascript"> function addOption(selectbox,text,value ) { var optn = document.createElement("OPTION"); optn.text = text; optn.value = value; selectbox.options.add(optn); } function addOption_list() { var month = new Array("January","February","March","April","May","June", "July","August","September","October","November","December"); for (var i=0; i < month.length;++i) { addOption(document.drop_list.Month_list, month[i], month[i]); } } </script> <body bgcolor="#ffffff" text="#000000" link="#0000ff" vlink="#800080" alink="#ff0000" onLoad="addOption_list()";> <FORM name="drop_list" method="POST" action="select"> <table> <tr> <td> <SELECT multiple="multiple" name="Month_list" size =8> <Option value="" >Month list</option> </SELECT> </td> <td><input type="submit" value = ">" id="submit" /></td> </form> </body> </html> And the output of this would be a list box which contains all months.. When i click, the '>' button, the value/values in the list box should get populated into another list box... any idea?? how to make this work?? Meena |
Darin McGrew |
Mar 5 2009, 12:00 PM
Post
#4
|
WDG Member Group: Root Admin Posts: 8,365 Joined: 4-August 06 From: Mountain View, CA Member No.: 3 |
This isn't about Markup, so I moved it to the Client-side Scripting forum.
|
Lo-Fi Version | Time is now: 25th April 2024 - 07:44 PM |