I have a table of employees and I need to show the salary of every employee of the selected month, so I need to pass two values into the function that is called on the onchange
, the value of the month with the employee id so to calculate the salary of the particular employee.
Salary section:
JavaScript:
<script>
function calSal(month,hidVal)
{
var mon = month.value;
alert(mon);
var hidVal = hidVal.value;
alert(hidVal);
}
</script>
PHP:
<?php
$query=mysqli_query($con,"select employee_first_name , employee_code ,e_id from add_employee");
$a=0;
while($result=mysqli_fetch_array($query))
{
$e_id[] = $result['e_id'];
$employee_first_name = $result['employee_first_name'];
$employee_code = $result['employee_code'];
?>
<tr>
<td align="center"><?php print_r ($e_id[$a]); ?><input type="hidden" value="<?php echo $e_id; ?>" id="id<?php echo $a; ?>"/></td>
<td align="center"><?php echo $employee_first_name. ' : ' .$employee_code; ?></td>
<td align="center">
<input type="text" value="<?php echo $a; ?>" id="hidVal<?php echo $a; ?>"/>
<select class="form-control select1" onchange="calSal(this, 'hidVal' );">
<option value="01">January</option>
<option value="02">Feburary</option>
<option value="03">March</option>
<option value="04">April</option>
<option value="05">May</option>
<option value="06">June</option>
<option value="07">July</option>
<option value="08">August</option>
<option value="09">September</option>
<option value="10">October</option>
<option value="11">November</option>
<option value="12">December</option>
</select>
</td>
<td align="center"></td>
</tr>
<?php
$a++;
}
?>
You are passing only 'hidVal'
as text with onchange="calSal(this, 'hidVal' );"
You have to pass $('#hidVal<?php echo $a; ?>')
there. So that you can grab value with hidVal.value
in javascript function.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.