• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Add options text to select from javascript?

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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

 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry Bear
I using jsp and java script
now everyone can help me add text to combo box??
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I will try
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 544
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Eric .I will show all code

 
Eric Pascarello
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
reply
    Bookmark Topic Watch Topic
  • New Topic