I have 2 dropdown outside the html table generated by PHP code. I have submit button in this table
as explained by following code.
<!doctype html>
Select Year:
<select name=\"year\" id=\"year\" style="width: 200px">
<option value=\"2014\">2014</option>
<option value=\"2015\">2015</option>
</select>
Select Trimester:
<select name=\"trimester\" id=\"trimester\" style="width: 200px">
<option value=\"1st\">1st</option>
<option value=\"2nd\">2nd</option>
<option value=\"3rd\">3rd</option>
</select>
<?php
while($row = mysql_fetch_array($result)){
$ict_id= $row['id'];
$name= $row['name'];
echo "<tr><form name=\"form$id\" id=\"form$id\"><td>".$name."</td>
<td>
<select name=\"absent$id\" id=\"absent$id\" style=\"width: 200px\">
<option value=\"1\">1</option>
<option value=\"2\">2</option>
</select>
</td>
<td>
<select name=\"creative$id\" id=\"creative$id\" style=\"width: 200px\">
<option value=\"1\">1</option>
<option value=\"2\">2</option>
</select>
</td>
<td>
<select name=\"problem$id\" id=\"problem$id\" style=\"width: 200px\">
<option value=\"1\">1</option>
<option value=\"2\">2</option>
</select>
</td>
<td>
<input type=\"button\" name=\"submit$id\" id=\"submit$id\" value=\"Submit\" onclick=\"getVal(this.id)\">
?>
On clicking this button it loads following javascript function.
function getVal(clicked_id){
}
My problem is how can I get the selected value of year and trimester and use inside the getVal function .
Any helps are welcomed.
Add onchange
event to the select element and pass id to this like this:
<select onchange="getVal(this.id)" name=\"absent$id\" id=\"absent$id\" style=\"width: 200px\">
Call getVal
function like this:
function getVal(clicked_id){
alert(clicked_id);
}
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.