2013-03-05 131 views
0

你能幫忙嗎?我現在有一個表格,它將第1,2和3框中的內容放在一起,並將它們放大並給出答案。我有一個單獨的函數和形式,可以減去框4-11(正如您從代碼中看到的那樣)。我需要幫助的是創建一個函數,它可以使用第二個函數並從第一個函數中減去它。Javascript和HTML表單 - 用一種形式創建兩個函數

如果有助於解釋我在做什麼,第一個函數將計算總收入。第二個計算的負支出,但現在我不知道如何從總額中減去支出?

基本上 - 我有答案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> 

回答

0

我認爲,如果你有你的職能,將工作返回值,就像這樣:

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; 
} 
相關問題