| Author |
Add options text to select from javascript?
|
Nguyen Phuoc
Greenhorn
Joined: Apr 23, 2011
Posts: 15
|
|
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
Joined: Jan 10, 2002
Posts: 56233
|
|
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?
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
Nguyen Phuoc
Greenhorn
Joined: Apr 23, 2011
Posts: 15
|
|
Sorry Bear
I using jsp and java script
now everyone can help me add text to combo box??
|
 |
Paul Clapham
Bartender
Joined: Oct 14, 2005
Posts: 16483
|
|
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
Joined: Apr 23, 2011
Posts: 15
|
|
|
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
Joined: Jan 10, 2002
Posts: 56233
|
|
|
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
Joined: Apr 23, 2011
Posts: 15
|
|
|
I will try
|
 |
Eric Pascarello
author
Rancher
Joined: Nov 08, 2001
Posts: 15357
|
|
What does that JavaScript look like when you view the page source?
Eric
|
 |
Nguyen Phuoc
Greenhorn
Joined: Apr 23, 2011
Posts: 15
|
|
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
Joined: May 14, 2004
Posts: 488
|
|
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
Joined: Apr 23, 2011
Posts: 15
|
|
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
Joined: Nov 08, 2001
Posts: 15357
|
|
Eric Pascarello wrote:What does that JavaScript look like when you view the page source?
Eric
|
 |
Nguyen Phuoc
Greenhorn
Joined: Apr 23, 2011
Posts: 15
|
|
Hi Eric .I will show all code
|
 |
Eric Pascarello
author
Rancher
Joined: Nov 08, 2001
Posts: 15357
|
|
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
Joined: Apr 23, 2011
Posts: 15
|
|
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
Joined: Nov 08, 2001
Posts: 15357
|
|
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
Joined: Apr 23, 2011
Posts: 15
|
|
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
Joined: Nov 08, 2001
Posts: 15357
|
|
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
|
 |
 |
|
|
subject: Add options text to select from javascript?
|
|
|