I created a 3-step form. the form is aimed to determine the price according to the number of employees entered. the user is entering the number of employees in the first step. JavaScript calculates the price according to this value. The index1.php form looks like this:
<form id="empnum" class="form-horizontal" method="GET" action="index2.php">
<label class="control-label">employee number</label>
<div class="controls">
<input type="text" class="span6 " id="employee_number" name="employee_number" required>
</div>
<button type="submit" class="btn btn-success">Calculate</button>
</form>
The js code is shown below;
function calculate(){
$.ajaxSettings.cache = false;
var employee_number = $("#employee_number").val();
function time(s) {
if(s>60){
hour=Math.floor(s/60);
mnts=s-(hour*60);
if(mnts==0){result= hour +' hour';}else{result= hour +' hour '+ mnts + ' mnts' ;}
}
else{result= s +' mnts';}
return result;
}
if (employee_number.length > 0)
{
// -------------------
a1=(employee_number*5)
a2=(employee_number*10)
a3=(employee_number*15)
$(".a1").html(time(a1)+" /month");
$(".a2").html(time(a2)+" /month");
$(".a3").html(time(a3)+" /month");
// -------------------
a1=(employee_number*10)
a2=(employee_number*20)
a3=(employee_number*40)
$(".b1").html(time(a1)+" /month");
$(".b2").html(time(a2)+" /month");
$(".b3").html(time(a3)+" /month");
// -------------------
if(employee_number>9 && employee_number<50){
$(".c3").html(time(employee_number*10)+" /month");
}
else if(employee_number>49 && employee_number<250){
$(".c3").html(time(employee_number*15)+" /month");
}
else if(employee_number>249){
$(".c3").html(time(employee_number*20)+" /month");
}
else
{
$(".c3").html("-");
}
}
}
html code which i added on index2.php
<table border="0" cellpadding="0" cellspacing="0" class="tb1">
<tr>
<th width="25%">danger level</th>
<th width="25%" class="bg1">doctor working time</th>
<th width="25%" class="bg2">expert's working time</th>
<th width="25%" class="bg3">duration of other staff</th>
</tr>
<tr>
<td><b>Less dangerous</b></td>
<td class="a1">0</td>
<td class="b1">0</td>
<td class="c1">-</td>
</tr>
<tr>
<td><b>dangerous</b></td>
<td class="a2">0</td>
<td class="b2">0</td>
<td class="c2">-</td>
</tr>
<tr>
<td><b>very dangerous</b></td>
<td class="a3">0</td>
<td class="b3">0</td>
<td class="c3">0</td>
</tr>
</table>
I also added jquery and js tags and onClick="calculate();
(inside button), but did not work again
How can I run JavaScript on the second page(index2.php) according to the value entered in the first page(index1.php)?
Note:It works fine on one page. But i have to make it dynamic with php(two page) because I will do attachments in the future.