I am trying to pull the information that the user inputs in the text boxes and pass the value to a JavaScript function in order to display the result in a "window.alert()" method.
I am currently using ASP.NET. This what I have so far for the ASP.NET front part and for the JavaScript;
<asp:Button ID="btnCalculateSalary" runat="server" Text="Calculate Salary" OnClick="calcFunction()" />
<script>
function calcFunction(c1, c2) {
c1 = document.getElementById('txtAnnualHours').value;
c2 = document.getElementById('txtPayRate').value;
return window.alert("Your Annual Salary is: " + c1 * c2);
}
OnClientClickfor your control, instead ofOnClick?OnClickfor server-side controls is to handle the server-side events. UseOnClientClickfor a client-side click handler. Note however that it is still a server-side control and may still cause a post-back refreshing the whole page.OnClicklooks for server-side code to execute, and you have nocalcFunction()method in your server-side code. What happens when you tryOnClientClickinstead?