Hide/Show child items on a dropdown onchange of the other dropdown value (parent)

I have simple filtering to be done possibly using javascript. I am new to javascript. I have a vehicle makeList and vehicle modelList coming from the java to my JSP.

            <tr><td><form:label path="makeId">Make: </form:label></td>
            <td><form:select  path="makeId" required="true">
                    <form:options items="${makeList}" itemValue="makeId" itemLabel="makeName"></form:options>
                </form:select>
            </td>
            <td><form:label path="modelId">Model: </form:label></td>
            <td><form:select path="modelId" required="true">
                    <form:options items="${modelList}" itemValue="modelId" itemLabel="modelName"></form:options>
                </form:select>
            </td></tr>

All I want to do is onchange of make , show only those model associated with that make and hide rest

Hope someone can get me a simplest solution

Answers


Solved

Following changes gave me the solution:

  1. Iterating the modelList and assigning the makeId to id

            <td><form:label  path="modelId">Model: </form:label></td>
            <td><form:select  path="modelId" required="true">
                     <c:forEach items="${modelList}" var="model">
                        <form:option value="${model.modelId}" id="${model.makeId}" ><c:out value="${model.modelName}"/></form:option>

                     </c:forEach>
                </form:select>
            </td>
  1. jquery onchange of Make dropdown:

$("#makeId").show( function() { var makeId = $(this).attr('value'); $("#modelId option[id !=" + makeId + "]").hide().attr("selected", false); $("#modelId option[id ="+makeId+"]").show().attr("selected",true); });


Need Your Help

Android Studio plugin is too old

android android-studio gradle android-gradle-plugin gradle-plugin

I was syncing fine and then suddenly when I tried to run a test on a device from Android Studio I started getting the error:

Delete rows based on range possible mistake

vba excel-vba range rows delete-row

I'm trying to delete rows on one worksheet based on a range in another worksheet. I think the problem here is probably something simple based on my limited VBA experience. Here is the code I've wr...