Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Display Text in Dropdown List

 
Fred Victa
Ranch Hand
Posts: 185
1
  • 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:

<tr>
<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>
<#else>
<OPTION value="${model.description}" >${model.description}</OPTION>
</#if>
</#list>
</#if>
</SELECT>
<INPUT class="adjust_input lotdisp_input" type=text id="model" name="model" value="${myCars.model!""}" maxlength="10">
</td>
</tr>


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)
{

modelCodesCount++;
}

}

if(modelCodesCount > 0)
{

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


}
else
{
$("modelOfVehicle").style.display ="none";
$("model").style.display ="";
$("model").value="";

}

},
onFailure : function()
{

}
}
);
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic