function check(){
var id;
id=document.getElementById("mat_id["+count_rows+"]").value;
<?php
$sql=mysql_query("SELECT mat_name FROM stock WHERE mat_id=''");
list($mat_name)=mysql_fetch_row($sql)or die (mysql_error());
?>
document.getElementById("mat_name["+count_rows+"]").value=<?php echo $mat_name ?>;
}