Reputation: 1607
I have two drop-downs and one text box. I want to display multiplication of selected values from both the drop-downs.
So i am trying to call a jquery function on "OnSelectedIndexChanged" even of dropdowns. Hoever I am getting error during build in Visual studio.
my code is :
<asp:DropDownList ID="ddlProbability" runat="server" Width="125px" OnSelectedIndexChanged="javascript:calculateRiskFactor();">
Errors are: Invalid expression term ':' and
Invalid expression term ')' and some more
Is anything wrong with syntax or this is wrong way to call a function?
The whole page code is something like this:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Submit_Risks.aspx.cs" Inherits="Risks_Submit_Risks" MasterPageFile="~/MasterPages/SAPMaster.master" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server"></asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
<script src="../Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
<script type="text/javascript" src="../Scripts/Validation.js"> </script>
<div class="container">
<div class="contain">
<div class="title">
Risks</div>
<div class="data">
<asp:Label runat="server" ID="lblMsg"></asp:Label>
<table class="style1" align="center">
<tr>
<td class="style2">
Probability (P)
</td>
<td class="style3">
<asp:DropDownList ID="ddlProbability" runat="server" Width="125px">
</asp:DropDownList>
<asp:RequiredFieldValidator ID="rfvProbability" runat="server" ControlToValidate="ddlProbability"
InitialValue="0" ValidationGroup="vgSubmit" ErrorMessage="Probability" ForeColor="Red"
Text="*" SetFocusOnError="True"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class="style2">
Impact (S)
</td>
<td class="style3">
<asp:DropDownList ID="ddlImpact" runat="server" Width="125px">
</asp:DropDownList>
<asp:RequiredFieldValidator ID="rfvImpact" runat="server" ControlToValidate="ddlImpact"
InitialValue="0" ValidationGroup="vgSubmit" ErrorMessage="Impact" ForeColor="Red"
Text="*" SetFocusOnError="True"></asp:RequiredFieldValidator>
</td>
</tr>
</div>
</div>
</div>
Upvotes: 0
Views: 10693
Reputation: 14737
As far as I can remember from ASP.NET WebForms, OnSelectedIndexChanged
only points back to a .NET server-side function, which ASP.NET calls with a postback (correct me if I'm wrong).
To bind client-side code to the control (like with jQuery), why not use jQuery to do it for you?
$('select[id$="ddlProbability"]').change(calculateRiskFactor);
Upvotes: 2
Reputation:
You have to register Client Side 'onchange'
event of DroDownlist..you can register the onchange
event using
DropDownList1.Attributes.Add("onChange", "return OnSelectedIndexChange();")
OnSelectedIndexChange()
is a javascript function that will be call when on client Side when DropDownListBox seleted index is changes.
Upvotes: 0
Reputation: 5386
Try this way.
<asp:DropDownList ID="ddlProbability" runat="server" Width="125px" OnSelectedIndexChanged="calculateRiskFactor()">
Upvotes: 0