File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes HTML, CSS and JavaScript and the fly likes Select element issue Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Select element issue" Watch "Select element issue" New topic
Author

Select element issue

Rajkumar balakrishnan
Ranch Hand

Joined: May 29, 2008
Posts: 445

Hi ranchers,
I am developing a Web App where i use AJAX to retrieve the data from DB and want to assign the value to a Combo Box...
Like if i get GTC as value, then i want the GTC value to be selected... Currently i am employing this code which retrieves the code from DB but not able to assign it to Combo box...

function stateChanged()
{
if (xmlHttp.readyState==4 && xmlHttp.status==200)
{
var xl = xmlHttp.responseText;
var selObj = document.getElementById('status');
selObj.options("GTC").selected = true;
}
}


But it wont work.... Please help me whats wrong with my code....
[ October 16, 2008: Message edited by: Bear Bibeault ]

Never try to be a hard-worker. Be a smart-worker.
My Blog
Sandip Sarkar
Ranch Hand

Joined: Nov 25, 2007
Posts: 55
Hi,

I faced a similar issue and i developed a work around this.
I got a unique ID created for every option of my combo box and then i did something like the following:

Suppose your option id is GTKID having the option value of "GTK" , then i display it as :


Hope it helps.
Thanks,
Sandip
Rajkumar balakrishnan
Ranch Hand

Joined: May 29, 2008
Posts: 445

Originally posted by Sandip Sarkar:
Hi,

I faced a similar issue and i developed a work around this.
I got a unique ID created for every option of my combo box and then i did something like the following:

Suppose your option id is GTKID having the option value of "GTK" , then i display it as :


Hope it helps.
Thanks,
Sandip


<select name="status">
<option value="0">- - Select something - -</option>
<option value="GTC">Given to Customer</option>
<option value="WTSTS">Waiting to Send to Supplier</option>
<option value="STS">Sent to Supplier</option>
</select>


What do i do in order to make Given to Customer selected if i get GTC as the retrieved value....
Sandip Sarkar
Ranch Hand

Joined: Nov 25, 2007
Posts: 55
Hi,

I changed your code as below:



I just tried making unique id's.
Now if you get the value of GTC (or anything else), simply append the "status" thing to the value and look up for the ID.
And then say selected as true on that as below:



Thanks,
Sandip
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
First off HTML does not have a "Combo box" element, it is just a select element.

To select a value in the list it is as simple as



now if it is a multiple select, you need to loop through the options and select it that way.



Eric
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61066
    
  66

Please read this for more information.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Rajkumar balakrishnan
Ranch Hand

Joined: May 29, 2008
Posts: 445

Thanks for all your help....
[ October 16, 2008: Message edited by: Rajkumar balakrishnan ]
 
Don't get me started about those stupid light bulbs.
 
subject: Select element issue