Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes HTML, CSS and JavaScript and the fly likes add values in select option using ajax and servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "add values in select option using ajax and servlet" Watch "add values in select option using ajax and servlet" New topic
Author

add values in select option using ajax and servlet

Vaishali Paramane
Ranch Hand

Joined: Mar 05, 2007
Posts: 106
Hi

I want to add values in select option depends of select values of other select option.

Front view I am using jsp and backend servlet





I can able to display values in textHint but I want to add these values in start_date select option.

Can anyone help me?

Thanks

Vaishali

SCJP, SCJD
Preparing for SCWCD
amit punekar
Ranch Hand

Joined: May 14, 2004
Posts: 507
Hello,
Give the "id" for start date and access it within your Javascript that fetches the values using Ajax. Once you get access to the drop down you can add values to it.
You should use Java script framework such as jQuery and its API documentation will help you to do this.

Regards,
Amit
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
You can not set the innerHTML of a select element in IE.

Easiest solution is to use jQuery since it handles it for you.

BUT if you can not use that library, I wrote a little function that tries to set the innerHTML. If setting the innerHTML results in no options being added, it rewrites the function so it will create an element and clone its options.


Running Example: http://jsbin.com/uqera4/


Eric>
Vaishali Paramane
Ranch Hand

Joined: Mar 05, 2007
Posts: 106
thanks Eric, but still its not working

I changed code




document.getElementById("txtHint").innerHTML=dateArray;
line instead of arrays i am getting output as [object]
I am very new in ajax, javascript.

Can anyone help me?

Thanks

Vaishali
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: add values in select option using ajax and servlet
 
Similar Threads
problem with sending # character through ajax
Struts Error: javax.servlet.jsp.JspException: Cannot find bean: "ListForm" in any scope
how to receive data in .jsp file from servlet in AJAX?
Ajax-Struts
How to display value in combo box using AJAX