Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

display stack array in select box

Status
Not open for further replies.

jsw15

Technical User
Jan 16, 2008
1
0
0
GB
hi, i have created a stack and am trying to display my stack array in a select box. any suggestions on how to do this would be appreciated.

Thanks

Jo
 
suggestion would be to write code. what is a stack? what have you tried? we don't write code for members, and we certainly don't write code for members who provide a one-sentence requirement.

 
I agree. The best suggestion would be to at least try.
 
Or ask your tutor.

Or read the class notes.

Or google for javascript populate select.

Or read any of the other 200 odd posts on the subject in this forum.

[sub]Never be afraid to share your dreams with the world.
There's nothing the world loves more than the taste of really sweet dreams.
[/sub]

Webflo
 
I assume by a "stack", you mean an array of objects? If so, you'll have to loop through this array and add each item to the select element. Do you know how to loop through arrays, or add one item to a select element?


-------------------------------------------------------

Mark,
[URL unfurl="true"]http://aspnetlibrary.com[/url]
[URL unfurl="true"]http://mdssolutions.co.uk[/url] - Delivering professional ASP.NET solutions
[URL unfurl="true"]http://weblogs.asp.net/marksmith[/url]
 
Try this:

Code:
var stack = ['one','two','tree'];
var sel = document.getElementById('myselect');
   for (var i=0,im=stack.length; i<im; i++)
   {
   sel.options[i] = new Option(stack[i]);
   }


- Lowet

[gray]Why can't all browsers parse pages the same way? It should be the Web designer who decides how to display the content, not the browser![/gray]
 
Lowet.......


I know you're new to the forum and all, but take note when other posters before you post something like dwarfthrower:

[!]Or ask your tutor.

Or read the class notes.[/!]

Or google for javascript populate select.

Or read any of the other 200 odd posts on the subject in this forum.

This question is very student-esque. The O.P has not provided a code example. They got 4 replies telling them basically to do their own work before you dropped a solution into their lap.

Since posting homework to the forum is not allowed, we should not be encouraging them to come back and get more answers. We're not expecting you to know every time a student posts a question, but please try to keep an eye out for the possibility. They are not people we want on the site. When I was in college I did my own homework, well... sometimes. I definitely did not ask people on the internet to do it for me. These students have teachers that are paid to help them when they have problems in class. Why should we do it for free?

-kaht

Lisa, if you don't like your job you don't strike. You just go in every day and do it really half-assed. That's the American way. - Homer Simpson

[small]<P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <.</B>[/small]
 
I understand. I'll think of that next time. This is actually the first forum that I've sent post in, so I'm new to the this. Well, thanx for the comment, kaht.

- Lowet

[gray]Why can't all browsers parse pages the same way? It should be the Web designer who decides how to display the content, not the browser![/gray]
 
What's more, posting completed solutions doesn't even help them. They'll take your code, use it in their assignment, their tutor will ask "So, why did you do it this way?", they won't be able to explain "their" code and will be shot down in flames anyway.

That and all your hard work (and any resulting stars that they might dish out) go down the gurgler when the thread gets red-flagged and deleted.

[sub]Never be afraid to share your dreams with the world.
There's nothing the world loves more than the taste of really sweet dreams.
[/sub]

Webflo
 
Well, then I don't feel sorry for him :p LOL
I'm the opposite. I would never paste any code in which I don't know how it works. :p

- Lowet

[gray]Why can't all browsers parse pages the same way? It should be the Web designer who decides how to display the content, not the browser![/gray]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top