My function. I get selected index when user change item in select:
$(function itemchange() {
var index = document.getElementById('columnList').selectedIndex;
if (index != -1) {
alert(index);
}
});
My html tags. I put select item in Panel. This Panel placed in modal window:
<asp:Panel ID="ModalPanel" runat="server" Width="700px" Height="500px" BackColor="GhostWhite">
<div>
<br />
<div style="float:left;">
<select size="4" id="columnList" onchange="itemchange" style="height:200px;">
<option value="Code">Code</option>
<option value="Name">Name</option>
<option value="P">P</option>
<option value="Desc">Desc</option>
<option value="Object">Object</option>
<option value="User name">User name</option>
<option value="Num">Num"</option>
<option value="Commant">Commant</option>
<option value="Prod">Prod</option>
<option value="Test">Test</option>
</select>
</div>
<div style="clear:left;">
<asp:Button ID="OKButton" runat="server" Text="Close" />
</div>
</div>
</asp:Panel>
You shouldn’t do:
Because now the scope of the function is not in the window object.
You should do:
Then the scope for the function changes to the window object and then it gets executed when you run
itemchange(). It will also run when the DOM is loaded (I believe you wanted that).