This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Select element issue

 
Rajkumar balakrishnan
Ranch Hand
Posts: 445
Android Eclipse IDE Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Sandip Sarkar
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 445
Android Eclipse IDE Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64708
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please read this for more information.
 
Rajkumar balakrishnan
Ranch Hand
Posts: 445
Android Eclipse IDE Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for all your help....
[ October 16, 2008: Message edited by: Rajkumar balakrishnan ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic