Thread: Setting the value of a textbox

1. Registered User
Join Date
Jan 2004
Posts
27

Unanswered: Setting the value of a textbox

Hi,

I want the users to be able to calculate the monthly/weekly repayments based on the amount of the loan.
When they hit submit, it calls a function & performs the calculations but I'm having trouble assigning the values into the monthly & weekly textboxes then.

Code:
```<script language="vbscript">
function calculate()
dim time, amt, total, int, intTotal, finalTotal, month, monthly, week, weekly
time = frmCal.txtDuration.value
amt = frmCal.txtAmt.value
int = 0.08

if CCur(time) = 1 then
month = 12
week = 52
ElseIf CCur(time) = 2 then
month = 24
week = 104
End If

intTotal = (CCur(amt) * CCur(int))
total = (CCur(intTotal) + CCur(amt))

monthly = (CCur(total) / CCur(month))
weekly = (CCur(total) / CCur(week))
Document.Write("Monthly Repayments: " & CCur(monthly) & "<br>")
Document.Write("Weekly Repayments: " & CCur(weekly))

end function
</script>

<body>
<form name="frmCal" action=# method="POST">
<table align=center border=1 width="394" rules="none">
<tr>
<th align=center width="194">Duration of Loan in Years</th>
<th align=center width="194">Amount to Borrow</th>
</tr>
<tr>
<td align=center width="194"><input type="text" name="txtDuration" value="" </td>
<td align=center width="194"><input type="text" name="txtAmt" value="" </td>
</tr>
<tr>
<td colspan = "2" align=center width="384"><input type="submit" name="cal" value="Calculate" onClick="calculate()">
</tr>
<tr>
<th align=center width="194">Monthly Repayments</th>
<th align=center width="194">Weekly Repayments</th>
</tr>
<tr>
<td align=center width="194"><input type="text" name="txtMonthly" value="" </td>
<td align=center width="194"><input type="text" name="txtWeekly" value="" </td>
</tr>
</table>```
Can someone tell what to do please...thanks*

2. Join Date
Jun 2003
Location
USA
Posts
1,032
With server-side VBScript (i.e. ASP code):

ASP Design Tips - Post Back Page
http://www.bullschmidt.com/devtip-postbackpage.asp

And:

Toward the top of the form (and Request.TotalBytes does NOT include any querystring variables):
<%
If Request.TotalBytes > 0 Then
LName = Request.Form("LName")
FName = Request.Form("FName")
Else
LName = ""
FName = ""
End If
%>

And here are the form fields themselves:
<input type="text" name="LName" value="<%= LName %>">
<input type="text" name="FName" value="<%= FName %>">