我昨天正在尝试通过在线资源学习 PHP。我有一个简单的程序(下面的代码)正在运行。我遇到的最后一个问题是当我单击按钮提交时,整个页面重新加载。
我想寻求您的帮助如何删除该事件。php脚本是否有可能通过不重新加载整个页面来执行?
我在网上读过几篇文章,上面说可以使用 ajax 来完成。不幸的是,我不知道该怎么做,因为我仍然是一个超级初学者。(哈哈)
<form method="POST">
Salary: <input id="salarytext" type="text" name="salary" onkeypress="return isNumberKey(event)"><br>
Membership Type:
<select name="membershiptype">
<option value="employed">Employed</option>
<option value="SE">Self Employed</option>
<option value="VM">Voluntary Member</option>
<option value="OFW">OFW</option>
</select>
<br/>
<input type="submit" />
</form>
<div class="SSSContributionComputation">
<?php
$a = (isset($_POST['salary'])) ? $_POST['salary'] : '';
$b = (isset($_POST['membershiptype'])) ? $_POST['membershiptype'] : '';
function employed($a, $b) {
if (empty ($a)) {echo "Type in your Salary to see the results.";}
elseif ($a <= 1249.99) {echo "Your Employer's (ER) Contribution is P80.70.<br>Your Contribution (EE) is P33.30.<br>Total amount credited to your SSS Account is P114.00";}
elseif ($a <= 1749.99) {echo "Your Employer's (ER) Contribution is P116.00.<br>Your Contribution (EE) is P50.00.<br>Total amount credited to your SSS Account is P166.00";}
elseif ($a <= 2249.99) {echo "Your Employer's (ER) Contribution is P151.30.<br>Your Contribution (EE) is P66.70.<br>Total amount credited to your SSS Account is P218.00";}
elseif ($a <= 2749.99) {echo "Your Employer's (ER) Contribution is P186.70.<br>Your Contribution (EE) is P83.30.<br>Total amount credited to your SSS Account is P270.00";}
elseif ($a <= 3249.99) {echo "Your Employer's (ER) Contribution is P222.00.<br>Your Contribution (EE) is P100.00.<br>Total amount credited to your SSS Account is P322.00";}
elseif ($a <= 3749.99) {echo "Your Employer's (ER) Contribution is P257.30.<br>Your Contribution (EE) is P116.70.<br>Total amount credited to your SSS Account is P374.00";}
elseif ($a <= 4249.99) {echo "Your Employer's (ER) Contribution is P292.70.<br>Your Contribution (EE) is P133.30.<br>Total amount credited to your SSS Account is P426.00";}
elseif ($a <= 4749.99) {echo "Your Employer's (ER) Contribution is P328.00.<br>Your Contribution (EE) is P150.00.<br>Total amount credited to your SSS Account is P478.00";}
elseif ($a <= 5249.99) {echo "Your Employer's (ER) Contribution is P363.30.<br>Your Contribution (EE) is P166.70.<br>Total amount credited to your SSS Account is P530.00";}
elseif ($a <= 5749.99) {echo "Your Employer's (ER) Contribution is P398.70.<br>Your Contribution (EE) is P183.30.<br>Total amount credited to your SSS Account is P582.00";}
elseif ($a <= 6249.99) {echo "Your Employer's (ER) Contribution is P434.00.<br>Your Contribution (EE) is P200.00.<br>Total amount credited to your SSS Account is P634.00";}
elseif ($a <= 6749.99) {echo "Your Employer's (ER) Contribution is P469.30.<br>Your Contribution (EE) is P216.70.<br>Total amount credited to your SSS Account is P686.00";}
elseif ($a <= 7249.99) {echo "Your Employer's (ER) Contribution is P504.70.<br>Your Contribution (EE) is P233.30.<br>Total amount credited to your SSS Account is P738.00";}
elseif ($a <= 7749.99) {echo "Your Employer's (ER) Contribution is P540.00.<br>Your Contribution (EE) is P250.00.<br>Total amount credited to your SSS Account is P790.00";}
elseif ($a <= 8249.99) {echo "Your Employer's (ER) Contribution is P575.30.<br>Your Contribution (EE) is P266.70.<br>Total amount credited to your SSS Account is P842.00";}
elseif ($a <= 8749.99) {echo "Your Employer's (ER) Contribution is P610.70.<br>Your Contribution (EE) is P283.30.<br>Total amount credited to your SSS Account is P894.00";}
elseif ($a <= 9249.99) {echo "Your Employer's (ER) Contribution is P646.00.<br>Your Contribution (EE) is P300.00.<br>Total amount credited to your SSS Account is P946.00";}
elseif ($a <= 9749.99) {echo "Your Employer's (ER) Contribution is P681.30.<br>Your Contribution (EE) is P316.70.<br>Total amount credited to your SSS Account is P998.00";}
elseif ($a <= 10249.99) {echo "Your Employer's (ER) Contribution is P716.70.<br>Your Contribution (EE) is P333.30.<br>Total amount credited to your SSS Account is P1,050.00";}
elseif ($a <= 10749.99) {echo "Your Employer's (ER) Contribution is P752.00.<br>Your Contribution (EE) is P350.00.<br>Total amount credited to your SSS Account is P1,102.00";}
elseif ($a <= 11249.99) {echo "Your Employer's (ER) Contribution is P787.30.<br>Your Contribution (EE) is P366.70.<br>Total amount credited to your SSS Account is P1,154.00";}
elseif ($a <= 11749.99) {echo "Your Employer's (ER) Contribution is P822.70.<br>Your Contribution (EE) is P383.30.<br>Total amount credited to your SSS Account is P1,206.00";}
elseif ($a <= 12249.99) {echo "Your Employer's (ER) Contribution is P858.00.<br>Your Contribution (EE) is P400.00.<br>Total amount credited to your SSS Account is P1,258.00";}
elseif ($a <= 12749.99) {echo "Your Employer's (ER) Contribution is P893.30.<br>Your Contribution (EE) is P416.70.<br>Total amount credited to your SSS Account is P1,310.00";}
elseif ($a <= 13249.99) {echo "Your Employer's (ER) Contribution is P928.70.<br>Your Contribution (EE) is P433.30.<br>Total amount credited to your SSS Account is P1,362.00";}
elseif ($a <= 13749.99) {echo "Your Employer's (ER) Contribution is P964.00.<br>Your Contribution (EE) is P450.00.<br>Total amount credited to your SSS Account is P1,414.00";}
elseif ($a <= 14249.99) {echo "Your Employer's (ER) Contribution is P999.30.<br>Your Contribution (EE) is P466.70.<br>Total amount credited to your SSS Account is P1,466.00";}
elseif ($a <= 14749.99) {echo "Your Employer's (ER) Contribution is P1,034.70.<br>Your Contribution (EE) is P483.30.<br>Total amount credited to your SSS Account is P1,518.00";}
elseif ($a <= 30000.00) {echo "Your Employer's (ER) Contribution is P1,090.00.<br>Your Contribution (EE) is P500.00.<br>Total amount credited to your SSS Account is P1,590.00";}
elseif ($a > 30000) {echo "You reached the maximum!<br>Your Employer's (ER) Contribution is P1,090.00.<br>Your Contribution (EE) is P500.00.<br>Total amount credited to your SSS Account is P1,590.00";}
}
function sevmofw($a, $b) {
if (empty ($a)) {echo "Type in your Salary to see the results.";}
elseif ($a <= 1249.99) {echo "Your Total Contribution (EE) is P104.<br>This amount will be credited to your SSS Account.";}
elseif ($a <= 1749.99) {echo "Your Total Contribution (EE) is P156.<br>This amount will be credited to your SSS Account.";}
elseif ($a <= 2249.99) {echo "Your Total Contribution (EE) is P208.<br>This amount will be credited to your SSS Account.";}
elseif ($a <= 2749.99) {echo "Your Total Contribution (EE) is P260.<br>This amount will be credited to your SSS Account.";}
elseif ($a <= 3249.99) {echo "Your Total Contribution (EE) is P312.<br>This amount will be credited to your SSS Account.";}
elseif ($a <= 3749.99) {echo "Your Total Contribution (EE) is P364.<br>This amount will be credited to your SSS Account.";}
elseif ($a <= 4249.99) {echo "Your Total Contribution (EE) is P416.<br>This amount will be credited to your SSS Account.";}
elseif ($a <= 4749.99) {echo "Your Total Contribution (EE) is P468.<br>This amount will be credited to your SSS Account.";}
elseif ($a <= 5249.99) {echo "Your Total Contribution (EE) is P520.<br>This amount will be credited to your SSS Account.";}
elseif ($a <= 5749.99) {echo "Your Total Contribution (EE) is P572.<br>This amount will be credited to your SSS Account.";}
elseif ($a <= 6249.99) {echo "Your Total Contribution (EE) is P624.<br>This amount will be credited to your SSS Account.";}
elseif ($a <= 6749.99) {echo "Your Total Contribution (EE) is P676.<br>This amount will be credited to your SSS Account.";}
elseif ($a <= 7249.99) {echo "Your Total Contribution (EE) is P728.<br>This amount will be credited to your SSS Account.";}
elseif ($a <= 7749.99) {echo "Your Total Contribution (EE) is P780.<br>This amount will be credited to your SSS Account.";}
elseif ($a <= 8249.99) {echo "Your Total Contribution (EE) is P832.<br>This amount will be credited to your SSS Account.";}
elseif ($a <= 8749.99) {echo "Your Total Contribution (EE) is P884.<br>This amount will be credited to your SSS Account.";}
elseif ($a <= 9249.99) {echo "Your Total Contribution (EE) is P936.<br>This amount will be credited to your SSS Account.";}
elseif ($a <= 9749.99) {echo "Your Total Contribution (EE) is P988.<br>This amount will be credited to your SSS Account.";}
elseif ($a <= 10249.99) {echo "Your Total Contribution (EE) is P1,040.<br>This amount will be credited to your SSS Account.";}
elseif ($a <= 10749.99) {echo "Your Total Contribution (EE) is P1,092.<br>This amount will be credited to your SSS Account.";}
elseif ($a <= 11249.99) {echo "Your Total Contribution (EE) is P1,144.<br>This amount will be credited to your SSS Account.";}
elseif ($a <= 11749.99) {echo "Your Total Contribution (EE) is P1,196.<br>This amount will be credited to your SSS Account.";}
elseif ($a <= 12249.99) {echo "Your Total Contribution (EE) is P1,248.<br>This amount will be credited to your SSS Account.";}
elseif ($a <= 12749.99) {echo "Your Total Contribution (EE) is P1,300.<br>This amount will be credited to your SSS Account.";}
elseif ($a <= 13249.99) {echo "Your Total Contribution (EE) is P1,352.<br>This amount will be credited to your SSS Account.";}
elseif ($a <= 13749.99) {echo "Your Total Contribution (EE) is P1,404.<br>This amount will be credited to your SSS Account.";}
elseif ($a <= 14249.99) {echo "Your Total Contribution (EE) is P1,456.<br>This amount will be credited to your SSS Account.";}
elseif ($a <= 14749.99) {echo "Your Total Contribution (EE) is P1,508.<br>This amount will be credited to your SSS Account.";}
elseif ($a <= 30000.00) {echo "Your Total Contribution (EE) is P1,560.<br>This amount will be credited to your SSS Account.";}
elseif ($a > 30000) {echo "You reached the maximum!<br>Your Total Contribution (EE) is P1,560.<br>This amount will be credited to your SSS Account.";}
}
if ($b == 'employed') {
employed($a, $b); //Pass the variables into the function from the outside.
}
elseif ($b == 'SE') {
sevmofw($a, $b);
}
elseif ($b == 'VM') {
sevmofw($a, $b);
}
elseif ($b == 'OFW') {
sevmofw($a, $b);
}
?>