Project code when changed , it will get the current selected pcode(Project code) id value and list the corresponding acode(Activity code) list in another select box(#acode) using ajax.
but when i try to list the value of particular value from mysql, pcode is listing and make if condition check with mysql record if match that pcode is select, but once change the pcode mysql acode instead of selecting acode it will list all acodes.
please help, what i wanna to do.
function check(t){
var id = t.id;
var val = t.options[t.selectedIndex].value;
$.ajax({
type: 'post',
url: 'code_verify.php',
data: {
project_code:val
},
success: function (response) {
document.getElementById("acode").innerHTML=response;
}
});
}
<p>My Database Name : timesheet</p>
<p>Table: projectcode</p>
<table width="250" border="1" cellspacing="0" cellpadding="0">
<tr>
<td align="center">id</td>
<td align="center">project</td>
<td align="center">pcode</td>Pcode
</tr>
<tr>
<td align="center">1</td>
<td>Library Time</td>
<td align="center">LB</td>
</tr>
<tr>
<td align="center">2</td>
<td>Leave</td>
<td align="center">L</td>
</tr>
</table>
<p>Table: activitycode</p>
<table width="250" border="1" cellspacing="0" cellpadding="0">
<tr>
<td align="center">id</td>
<td align="center">pcode</td>
<td align="center">activity</td>
<td align="center">acode</td>
Pcode </tr>
<tr>
<td align="center">1</td>
<td align="center">1</td>
<td align="center">Bench</td>
<td align="center">B</td>
</tr>
<tr>
<td align="center">2</td>
<td align="center">2</td>
<td align="center">Sick Leave</td>
<td align="center">Sl</td>
</tr>
<tr>
<td align="center">3</td>
<td align="center">2</td>
<td align="center">Causal Leave</td>
<td align="center">CL</td>
</tr>
<tr>
<td align="center">4</td>
<td align="center">2</td>
<td align="center">Loss of Pay</td>
<td align="center">LP</td>
</tr>
</table>
<p>Table: user_timesheet</p>
<table width="250" border="1" cellspacing="0" cellpadding="0">
<tr>
<td align="center">id</td>
<td align="center">userid</td>
<td align="center">pcode</td>
<td align="center">acode</td>
</tr>
<tr>
<td align="center">1</td>
<td align="center">1</td>
<td align="center">1</td>
<td align="center">1</td>
</tr>
<tr>
<td align="center">2</td>
<td align="center">1</td>
<td align="center">2</td>
<td align="center">2</td>
</tr>
<tr>
<td align="center" bgcolor="#666666">3</td>
<td align="center" bgcolor="#666666">1</td>
<td align="center" bgcolor="#666666">2</td>
<td align="center" bgcolor="#666666">3</td>
</tr>
<tr>
<td align="center">4</td>
<td align="center">1</td>
<td align="center">2</td>
<td align="center">4</td>
</tr>
</table>
<p></p>
<p> </p>
<p> </p>
<table width="250" border="1" cellspacing="0" cellpadding="0">
<tr>
<td>
<select name="pcode_1" id="1" class="pcode" onChange="check(this);">
<?php
$sql=mysql_query("select * from user_timesheet where id=3");
while($row=mysql_fetch_array($sql)){
$leave=mysql_query("SELECT * FROM projectcode"); while($leave1=mysql_fetch_array($leave)) { ?>
<option value="<?=$leave1['id']?>" <?php if($leave1['id']==$row['pcode']){ echo "selected";}?>> <?=$leave1['pcode']?> </option>
<?php } } ?>
</select></td>
<td><select name="acode" id="acode"></select></td>
</tr>
</table>
<?php
$project_code = $_POST['project_code'];
$find=mysql_query("select * from activitycode where pcode=$project_code");
while($row=mysql_fetch_array($find))
{
echo "<option value='$row[id]'>".$row['acode']."</option>";
}
?>
<p> </p>
<p>i am trying to list the record as below query <br/><br/>
" select * from user_timesheet where id=3 " </p>
<p> </p>
<strong><u> Output: (currently coming)</u></strong><br/><br/>
//While change Project code , ajax(using project code ID) return all activity code corresponding to pcode from activitycode table,
<br/><br/>
Then list record with user_timesheet where id=3, need to select automatic corrponding ID, pcode and acode wanna to select.
<table width="250" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>Project Code :
<select name="pcode_1" id="1" class="pcode" onChange="check(this);">
<option value="1">Library Time </option>
<option value="2" selected="selected">Leave</option>
</select></td>
<td>Activity Code:
<select name="acode" id="acode">
<option value="1">Sick Leave</option>
<option value="2">Causal Leave</option>
<option value="3">Loss of Pay</option>
</select></td>
</tr>
</table>
<br/><br/>
<strong><u> Expecting Output: </u></strong><br/><br/>
<table width="250" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>Project Code :
<select name="pcode_1" id="1" onChange="check(this);">
<option value="1">Library Time </option>
<option value="2" selected="selected">Leave</option>
</select></td>
<td>
Activity Code:
<select name="acode" id="acode">
<option value="1">Sick Leave</option>
<option value="2" selected="selected">Causal Leave</option>
<option value="3">Loss of Pay</option>
</select></td>
</tr>
</table>
</div>