[英]Javascript and HTML form - Creating two functions with one form
你能幫忙嗎? 我現在有一個表格,其中包含方框1、2和3中的內容,並將它們乘以並給出答案。 我有一個單獨的函數和形式,它減去框4-11(從代碼中可以看到)。 我需要幫助的是創建一個可以使用第二個函數並將其從第一個函數中減去的函數。
如果它有助於解釋我在做什么,則第一個函數將計算總收入。 第二個計算負支出,但現在我不知道如何從毛額中減去支出?
基本上-我有一個回答A(總數)的函數。 我有回答B(費用)的功能。 但是,如何從A中減去B?
任何幫助將是巨大的!
<script language="javascript" type="text/javascript">
function runGross(grossForm) {
var field1 = Number(grossForm.box1.value);
var field2 = Number(grossForm.box2.value);
var field3 = Number(grossForm.box3.value);
grossForm.total.value = '$' + field1*field2*field3;
}
function runTotal(totalForm) {
var field4 = Number(totalForm.box4.value);
var field5 = Number(totalForm.box5.value);
var field6 = Number(totalForm.box6.value);
var field7 = Number(totalForm.box7.value);
var field8 = Number(totalForm.box8.value);
var field9 = Number(totalForm.box9.value);
var field10 = Number(totalForm.box10.value);
var field11 = Number(totalForm.box11.value);
totalForm.total.value = field4-field5-field6-field7-field8-field9-field10-field11;
}
</script>
<h1>How Much Can You Make as Counselor in Private Practice?</h1>
<h2><span style="color: #339966;">Adding the Total Gross Revenue</span></h2>
Use an average of cash clients and various payers. Remember, that insurance pays a little more for first appointments, and couples counseling / family therapy.
<form><span style="color: #339966;"><strong>Revenue Per Session</strong></span>: <input type="text" name="box1" size="10" maxlength="20" placeholder="Avg 50-150" />
<br/><br/>
30-35 sessions a week is traditionally fulltime. Some clinicians work more, some work less.
<br/>
<span style="color: #339966;"><strong>Sessions Per Week:</strong></span><input type="text" name="box2" size="10" maxlength="20" placeholder="Avg. 30-35"/>
<br/>
<br/>
Recommended: 48 weeks per year. That allows for 4 weeks off per year.
<br/>
<span style="color: #339966;"><strong>Weeks Per Year</strong>:</span> <input type="text" name="box3" size="10" maxlength="20" placeholder="Avg. 48-50" />
<br/>
<br/>
<strong><span style="color: #339966;">Your Total Gross Revenue:</span> </strong>
<input onclick="runGross(this.form)" type="button" value="Calculate My Gross Revenue" />
<input type="text" name="total" size="10" maxlength="20" />
</form>
<h2><span style="color: #ff0000;">Subtracting the Expenses</span></h2>
Remember to include heat, electric, water, and Internet (if applicable).
<form><span style="color: #ff0000;"><strong>Rent & Utilities (per year):</strong></span> <input type="text" name="box4" size="10" maxlength="20" />
<br/>
<br/>
Some providers in private practice spend around 7% of revenue. Others spend 0%.
<br/>
<span style="color: #ff0000;"><strong>Marketing:</strong></span><input type="text" name="box5" size="10" maxlength="20" />
<br/>
<br/>
Will you hire a billing company (calculate 5% of revenue)? Accept credit cards (calculate 2% of revenue)?
<br/>
<span style="color: #ff0000;"><strong>Medical Billing</strong>:</span> <input type="text" name="box6" size="10" maxlength="20" />
<br/>
<br/>
These can be under $300 a year if you’re frugal, or thousands if you plan to attend conferences.
<br/>
<span style="color: #ff0000;"><strong>CEUs and Association Fees:</strong></span> <input type="text" name="box7" size="10" maxlength="20" />
<br/>
<br/>
Professional Liability insurance is approx $150-$350 a year.
<br/>
<span style="color: #ff0000;"><strong>Insurance:</strong></span> <input type="text" name="box8" size="10" maxlength="20" />
<br/>
<br/>
For a solo-practice, can be around $2500 a year.
<br/>
<span style="color: #ff0000;"><strong>Office Expenses:</strong></span> <input type="text" name="box9" size="10" maxlength="20" />
<br/>
<br/>
Approx $500 a year for Legal Expenses.
<br/>
<span style="color: #ff0000;"><strong>Accounting and Legal:</strong></span> <input type="text" name="box10" size="10" maxlength="20" />
<br/>
<br/>
Estimate another $1500 for the unexpected!
<br/>
<span style="color: #ff0000;"><strong>Misc. Expenses:</strong></span> <input type="text" name="box11" size="11" maxlength="20" />
<br/>
<br/>
<strong><span style="color: #339966;">Your Total Pre-Tax (Pre-Tax):</span> </strong>
<strong></strong><input onclick="runTotal(this.form)" type="button" value="Calculate My Total" />
<input type="text" name="total" size="20" maxlength="20" />
</form>
我認為如果您的函數返回值,它將像下面這樣工作:
var runGross = function (grossForm)
{
//contents here
return grossForm.total.value;
}
和
var runTotal = function (totalForm)
{
//contents here
return totalForm.total.value;
}
然后,如果您想讓另一個函數找到不同之處:
var findProfit = function (runGross, runTotal)
{
return runGross - runTotal;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.