I am developing an web application with vb.net and asp.net.
In this web application one of the web form is like below New status (required)
the options/data shown in the above drop-down list is coming from data base and they are conditional as well. these options are not fixed all the time. they are visible depending on a previous selection by the user.
Among those data there are 3 data for which I want to display 3 different input types. the id of these 3 option/data are 10, 11 and 12.
I want to display different input type below this drop-down list depending on the selected data in the drop-down list.
Example
If in the drop down list the selected data id is 10 I want to display a text box below the dropdown list
<div class="form-element">
<label>Offered salary (numeric only!!)</label>
<input type="text" id="txtOfferedSalary" class="txtOfferedSalary" runat="server" data-bind="value:offeredSalary, valueUpdate: 'afterkeydown'" />
</div>
If in the drop down list the selected data id is 12 I want to display a calender below the dropdown list
<div class="form-element">
<label>
Start date (required if job offered, format: DD-MMM-YYYY)
</label>
<div class="input-append">
<span class="add-on "><span class="icon-calendar"></span></span>
<input class="dp" size="16" type="text" value="" runat="server" id="txtStartDate" />
</div>
</div>
For the rest of the data I dont want to do anything. How can I do it with javascript? Please help me with code.
Thank you
Edited code
<%@ Page Title="" Language="VB" MasterPageFile="~/_resx/E4_Popup.master" AutoEventWireup="false" CodeFile="update-status_popup.aspx.vb" Inherits="E4_Jobs_Details_Application_update_status" %>
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="Server">
<div class="form-element">
<label>New status (required)</label>
<select id="comNewStatus" runat="server" datavaluefield="id" datatextfield="name" class="nFee" onchange="displayDiv()"></select>
</div>
<div id="cal" class="form-element">
<label>
Start date (required if job offered, format: DD-MMM-YYYY)
</label>
<div class="input-append">
<span class="add-on "><span class="icon-calendar"></span></span>
<input class="dp" size="16" type="text" value="" runat="server" id="txtStartDate" />
</div>
</div>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ScriptContent" runat="Server">
<script type="text/javascript">
function displayDiv() {
if ($("#comNewStatus").val() == "1") {
$("#cal").show();
}
else {
$("#cal").hide();
}
}
function RefreshParent() {
if (window.opener != null && !window.opener.closed) {
window.opener.location.reload();
}
}
window.onbeforeunload = RefreshParent;
</script>
</asp:Content>
all the references of jquery and ko-js have been made in the master file.
Add jquery and add Id's to your divs, hide them by default (display:none) and then display them on the onchange event of the select control.
Edit: added proper control id resolving in case of master/detail pages.