This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes HTML, CSS and JavaScript and the fly likes Ajax : how to replace another option list? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Ajax : how to replace another option list?" Watch "Ajax : how to replace another option list?" New topic
Author

Ajax : how to replace another option list?

Nakata kokuyo
Ranch Hand

Joined: Apr 13, 2005
Posts: 438
Good day everyone, i'm new to ajax, and having my try using prototype

if i have 2 select option list, say seletOption and updateOption , when onchange on seletOption, updateOption will update and change value based on choice of seletOption



the callAjax() function as follow :



my doubt are :

1)how do we update the updateOption ?
2)for generate the choice of updateOption, i was thinking return a xml which contains all value for updateOption in following format



- in prototype, is there a way to parse xml ? or normally how to parse xml in usual?
- is it good to return xml in this case ? any other choices ?

many thanks in advance for guidance
[ October 11, 2006: Message edited by: Nakata kokuyo ]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60748
    
  65

Originally posted by Nakata kokuyo:
1)how do we update the updateOption ?


The select element has an API that can be used to manipulate it. You should have a JavaScript and HTML DOM reference handy. Without such a reference you will continually struggle.


2)for generate the choice of updateOption, i was thinking return a xml which contains all value for updateOption in following format


Not a great choice. Returning a JSON structure that you can easily traverse with JavaScript would be much easier.

- in prototype, is there a way to parse xml ? or normally how to parse xml in usual?


If you decide to ue XML, you would parse it as usual given the XML document returned by the XHR instance. Prorotype's $A() function will help you traverse node lists.

is it good to return xml in this case ? any other choices ?


See above.
[ October 11, 2006: Message edited by: Bear Bibeault ]

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Nakata kokuyo
Ranch Hand

Joined: Apr 13, 2005
Posts: 438
thank you and have a nice day, Bear Bibeault ,

do you mind to show me the most useful and frequent reference on javascript and DOM reference as you mentioned ?

thanks again for guidance , bear
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60748
    
  65

I use a combination of the following two books:

http://www.amazon.com/exec/obidos/ASIN/0596000480/jr_bunk-20

http://www.amazon.com/Dynamic-HTML-Definitive-Reference-2nd/dp/0596003161/sr=8-1/qid=1160615772/ref=pd_bbs_1/002-4891816-5349605?ie=UTF8&s=books

and online references such as

http://www.w3schools.com/
Nakata kokuyo
Ranch Hand

Joined: Apr 13, 2005
Posts: 438
thanks Bear Bibeault for the guidance
Nakata kokuyo
Ranch Hand

Joined: Apr 13, 2005
Posts: 438
hi bear, i have figure out how to replace the option list, but somehow i have some question on it , i have xml file in format as follow :


and have 2 option list as follow :
when "myoption" onchange, it will change the option in "changeoption"



and below is the callback function to replace "changeoption" option



this code work fine and it does replace the changeoption, however if i replace the line



to



it didn't give any error but the changeoption list is not change, i did output retLabel and retValue, it show the value correctly ,besides, i also try on using new String(retLabel), but it doesn't help

why is it so ?
thank you
[ October 12, 2006: Message edited by: Nakata kokuyo ]
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Ajax : how to replace another option list?
 
Similar Threads
Struts - Ajax - Popup window question
how do get selected value from combobox in html
JSP select with multiple options
help with Prototype
Fill combo using properties file