This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes HTML, CSS and JavaScript and the fly likes JAVA SCRIPT Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "JAVA SCRIPT" Watch "JAVA SCRIPT" New topic
Author

JAVA SCRIPT

BISWAS RAHUL
Greenhorn

Joined: Oct 21, 2001
Posts: 4
HOW DO I POPULATE AN HTML LISTBOX DYNAMICALLY USING JAVA SCRIPT?
I'VE TRIED USING ADD METHOD BUT FAILED. KINDLY LET ME KNOW AS TO HOW TO GO ABOUT WITH IT.
Terence Doyle
Ranch Hand

Joined: May 30, 2001
Posts: 328
HI,
Where are you going to get the options to populate the list with? What type of page is this? Is this script server-side or client-side?
Without more information it's a bit difficult to help you. Anyway here's a basic scenario that might help you:
The basic idea would be to assign values to the list box at page construction time, so you will need to have your list of retrievable values at that time.
Lets imagine you have your values in an object called 'values' (could be an array, a collection,...) and another object that contains the names corresponding to those values called 'names'
Then simply use a for loop like this:

Hope that helps,

------------------
Terry Doyle
Sun Certified Programmer for Java 2 Platform


Raising Flares debut album 'Ignition' out now

http://www.raisingflares.com

Terry Doyle <br />SCPJ 1.4 , SCWCD , SCMAD(Beta)
BISWAS RAHUL
Greenhorn

Joined: Oct 21, 2001
Posts: 4
I'm using client side scripting

Originally posted by BISWAS RAHUL:
HOW DO I POPULATE AN HTML LISTBOX DYNAMICALLY USING JAVA SCRIPT?
I'VE TRIED USING ADD METHOD BUT FAILED. KINDLY LET ME KNOW AS TO HOW TO GO ABOUT WITH IT.

Mike Curwen
Ranch Hand

Joined: Feb 20, 2001
Posts: 3695

Then let's move it to the client side forum...

Shivkumar Soni
Greenhorn

Joined: Nov 02, 2001
Posts: 2
Hi,
If you are coding in JSP, then you can dynamically populate the combo box like this:
<select>
<%
for( i=0;i<10;i++)
{
%>
<option value=<%=i%>></option>
<%}%>
</select>

Pl let me know if this is the answer to your query
Thanks,
Shivkumar Soni
 
GeeCON Prague 2014
 
subject: JAVA SCRIPT