File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Other Application Frameworks and the fly likes Display Text in Dropdown List Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Other Application Frameworks
Bookmark "Display Text in Dropdown List" Watch "Display Text in Dropdown List" New topic

Display Text in Dropdown List

Fred Victa
Ranch Hand

Joined: May 01, 2008
Posts: 173
I have an application and it has a webpage that displays various drop down menus. I have drop down menus for the makes and models of a vehicle. When I select the make of a vehicle, I would like to have the drop down menu for model to say, "Select Model of Vehicle". My drop down menu displays the vehicle models, but it does not display "Select Model of Vehicle." How can I get it to display that?

Here is a snippet from one of my freemarker templates:

<td class="cellpadding2"> </td>
<td class="normalfont cellpadding2"><@spring.message code="page.fieldLabel.model" /></td>
<td class="cellpadding2">
<SELECT name="modelOfVehicle" id="modelOfVehicle">
<OPTION value=""><@spring.message code=""/></OPTION>
<#if vehicleModels??>
<#list vehicleModels as model>
<#assign selected=""/>
<#if model.description?trim == myCars.modelOfVehicle?trim >
<#assign selected = "selected"/>
<OPTION value="${model.description}" selected> ${model.description}</OPTION>
<OPTION value="${model.description}" >${model.description}</OPTION>
<INPUT class="adjust_input lotdisp_input" type=text id="model" name="model" value="${myCars.model!""}" maxlength="10">

Here is a snippet from my Javascript file:

new Ajax.Request(message.vehicleModelListURL,
method: "post",
parameters: "selectedMake="+selectedMake,
onComplete: function(transport)
var modelCodes = transport.responseText.split('|');
var modelCodesCount = 0;

$("modelOfVehicle").options.length = 0;
$("modelOfVehicle").options[0] = new Option("Select Model","");

for (var i=0; i < modelCodes.length; i++)
$("modelOfVehicle").options[i+1] = new Option(trimWS(modelCodes[i]),trimWS(modelCodes[i]));

if (modelCodes[i].trim().length > 0)



if(modelCodesCount > 0)

$("model").style.display ="";
$("modelOfVehicle").value = model;

$("modelOfVehicle").style.display ="none";
$("model").style.display ="";


onFailure : function()

I agree. Here's the link:
subject: Display Text in Dropdown List
It's not a secret anymore!