Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Add options text to select from javascript?

 
Nguyen Phuoc
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all
Please help me add text to combo box from java script??
text load from database and it static
my js

html combobox

 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64631
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There's no such thing as a combo box in HTML. I have fixed the subject for you.

You say JavaScript, but then show JSP code full of Java. Which is it that you want?
 
Nguyen Phuoc
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry Bear
I using jsp and java script
now everyone can help me add text to combo box??
 
Paul Clapham
Sheriff
Pie
Posts: 20764
30
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's the problem, then. HTML doesn't have a combo box, it just has a <select> element. You can't add text to a <select> element, you can only provide it with a list of options.

Or perhaps you could show us the Javascript you want to generate?
 
Nguyen Phuoc
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wrong .HTML doesn't have a combo box.by this way (above code) I added value to select but list options is blank
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64631
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You still have not answered the question: are you trying to do this in JavaScript or in Java? On the server or on the client?
 
Nguyen Phuoc
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I will try
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What does that JavaScript look like when you view the page source?

Eric
 
Nguyen Phuoc
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks All !
I added options text to select .But for loop in java script cannot loop jsp scriptlet .

Are you solutions?
PS:My projecter dont allow use JSTL
 
amit punekar
Ranch Hand
Posts: 544
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

String j = listCatolog.get(f).toString();


It seems that you are not incrementing "f" anywhere so you are getting same value from the ArrayList.

You can use jQuery as well to do this which is more cleaner and nicer approach to handle such scenarios.


Regards,
amit
 
Nguyen Phuoc
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
amit punekar wrote:Hello,

String j = listCatolog.get(f).toString();


It seems that you are not incrementing "f" anywhere so you are getting same value from the ArrayList.

You can use jQuery as well to do this which is more cleaner and nicer approach to handle such scenarios.


Regards,
amit

Uhm.I think so
But I don't know jQuery
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Eric Pascarello wrote:What does that JavaScript look like when you view the page source?

Eric
 
Nguyen Phuoc
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Eric .I will show all code

 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nguyen Phuoc wrote:Hi Eric .I will show all code


I do not care about the serverside code, I care about what is generated to the page that the JavaScript actually sees. View page source in the browser, grab that code.

Eric
 
Nguyen Phuoc
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Eric Pascarello wrote:
Nguyen Phuoc wrote:Hi Eric .I will show all code


I do not care about the serverside code, I care about what is generated to the page that the JavaScript actually sees. View page source in the browser, grab that code.

Eric

OK men

 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So that code runs fine.

I am guessing that is not what you want. I am guessing that the select options should be different and be from something on the server.

In that case you can not just use plain old jsp to write the values to the page. You are going to have to learn about Ajax. Look into linked selects or double combos.

Eric
 
Nguyen Phuoc
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Eric Pascarello wrote:So that code runs fine.

I am guessing that is not what you want. I am guessing that the select options should be different and be from something on the server.

In that case you can not just use plain old jsp to write the values to the page. You are going to have to learn about Ajax. Look into linked selects or double combos.

Eric

Thank eric
that code run fine but i see problem at

for loop in javascript dont run jsp that code .When this select box "parentId" blank(value added but text blank)
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JavaScript and JSP run in two different places. They can not interact with one another. Nice article: http://www.javaranch.com/journal/200510/Journal200510.jsp#a1

Eric
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic