• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

Display Text in Dropdown List

Ranch Hand
Posts: 215
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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="page.option.select.model"/></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()

It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!