user2366467 user2366467 - 3 months ago 13
ASP.NET (C#) Question

Form calc field not post on report page jquery and asp

Need help with this code. I have a form that does a calculation using the input fields using jquery, but when I submit the form the total or calculated field does not print on my output page. Can anyone help

Form Code

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
<link href="Style/finance.css" rel="stylesheet" type="text/css">
<script src="http://jsfiddle.net/echo/jsonp/"></script>
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.0/jquery-ui.js"></script>
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.0/themes/base/jquery-ui.css">
<script>
$(document).on('ready',function() {
$( ".datepicker" ).datepicker({ dateFormat: 'M-yy' });
});
$(document).ready(function() {
$('input').keyup(function(){ // run anytime the value changes

var days = parseFloat($('#days').val()); // get value of field
var balance = parseFloat($('#balance').val()); // convert it to a float
var rate1 = parseFloat($('#rate1').val());

$('#ans1').html(balance * rate1 * days); // add them and output it
});
});

</script>
</head>

<body>

<form action="test.asp" method="post">
<table>
<tr>
<td><label>Company Name (invoice From):</label></td>
<td> <select name="fromcompany" required id="fromcompany" tabindex="1" title="fromcompany">
<option>New </option>
<option>AuD</option>
<option>NZ</option>
<option>China</option>
<option>Asia</option>
<option>Other</option></select></td></tr>

<tr>
<td><label>A.B.N</label></td>
<td><select name="abn" id="abn" tabindex="2" title="abn">
<option>12 345 678 901</option>
<option>34 345 678 901</option>
<option>56 345 678 904</option>
<option>89 123 456 789</option>
</select></td>
</tr>

<tr>
<td><label>Company Name (invoice To):</label></td>
<td><select name="tocompany" required id="tocompany" tabindex="3" title="tocompany">
<option>New </option>
<option>Aus</option>
<option>NZ</option>
<option>ABC</option>
<option>XYZ</option>
<option>Other</option></select></td></tr>
<tr><td><label>Invoice No:</label></td><td><input name="invno" required id="invno" tabindex="4" title="invno"></td></tr>

<tr><td><label>Month</label></td><td><p><input type="text" name="datepicker" id="datepicker" class="datepicker"></p></td></tr>

<tr><td><label>Rate:</label></td><td><input type="input" name="rate1" id="rate1"/></td></tr>
<tr><td><label>Balance:</label></td><td><input type="input" name="balance" id="balance"/></td></tr>
<tr><td><label>Days:</label></td><td><input type="input" name="days" id="days"/></td></tr>


<tr><td><label>Interest Amount:</label></td><td><div><span style="clear:both;" name="ans1" id="ans1" readonly="true"></span><br></div></td></tr>

</table>
<input type="submit">
</form>
</body>
</html>


Below is the code for the asp page

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
<link href="Style/finance.css" rel="stylesheet" type="text/css">
</head>

<body>
From: <% response.write(request.form("fromcompany")) %><br>
To: <% response.write(request.form("tocompany")) %><br>
Balance: <% response.write(request.form("balance")) %><br>
Days: <% response.write(request.form("days")) %><br>
Interest Rate: <% response.write(request.form("rate1")) %><br>
Total: <% response.write(request.form("total1")) %><br>
Irate<% response.write(request.form("rate1")) %><br>
Irate<% response.write(request.form("rate1")) %><br>
Inv No: <% response.write(request.form("invno")) %><br>
Output: <%="o"%><br>

</body>
</html>


With the output, everything works except for the total

Any help would be appreciated

Answer

You're looking for a form field named total1:

request.form("total1")

But there is no such field in the HTML. Add one (make sure it's within the form element):

<input type="text" name="total1" id="total1" />

Then write the value to that with jQuery:

$('#total1').val(balance * rate1 * days);
Comments