This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes HTML, CSS and JavaScript and the fly likes Select problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Select problem" Watch "Select problem" New topic
Author

Select problem

Don Martino
Greenhorn

Joined: Oct 04, 2008
Posts: 25
I'm retreiving a value from a d/b and want to display correct entry when page is loaded.
If database_type = "GEN", how would I get the GEN entry to display?


<select name="type" onchange=''>
<option value="DIG">DIG</option>
<option value="ENR">ENR</option>
<option value="GEN">GEN</option>
<option value="MUS">MUS</option>
<option value="PRO">PRO</option>
<option value="QUE">QUE</option>
<option value="REF">REF</option>
<option value="RES">RES</option>
<option value="TDD">TDD</option>
</select>
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60794
    
  65

Put the selected attribute on the option.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
You what it to be selected by default? Than add the selected attribute to the tag.

Eric
[ October 30, 2008: Message edited by: Eric Pascarello ]
Don Martino
Greenhorn

Joined: Oct 04, 2008
Posts: 25
I don't want a specific value displayed as default each time the page loads. I want the value I capture from the d/b record to be displayed, which could be GEN or any of the values listed in the options.

I was just using the "If database_type = "GEN".... as an example, but it will be different each time a new d/b rec is read.
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
I still have no clue what you are trying to do exactly.

Eric
Don Martino
Greenhorn

Joined: Oct 04, 2008
Posts: 25
if database_value = "DIG", how do I get the "DIG" entry in select option to display?

Could I create a js function?

function dropdown(){

document.getElementById("type").value = document.getElementById("database_value").value;

}
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60794
    
  65

Are you using JSP, PHP, something else, on the back end?

If so, that's where you'd set the selected option.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Select problem
 
Similar Threads
Difference between resource-ref and env-entry
String resource references in Web.xml using RAD 7.5
JDO
Configuring Mail Session for Orion
ArrayList in http response.