ผมลองใส่ var id1 = document.getElementById('showdiv1');
var id2 = document.getElementById('showdiv2'); และลองเปลี่ยน var id = document.getElementById('showdiv1');
var id = document.getElementById('showdiv2'); <td><div id1='showdiv1'></div></td>
<td><div id2='showdiv2'></div></td>
ไม่แสดงผลลัพธ์อะไรเลย
Code (PHP)
<!doctype html>
<html>
<head>
<meta charset="utf8">
<title>select onchange</title>
<script>
function slc_onchange(val){
var id1 = document.getElementById('showdiv1');
var id2 = document.getElementById('showdiv2');
var inp=document.getElementsByTagName('input'); inp.item(0).value=val;
var clsinp=document.getElementsByClassName('showclass');
var ln=clsinp.length;
for( var i=0; i<ln; i++){ clsinp[i].value=val;}
}
</script>
</head>
<?
mysql_connect("localhost","root","123456") or die(mysql_error());
mysql_select_db("mydatabase");
?>
<body>
<select name="lmName1" onchange="slc_onchange(this.value)">
<option value=""><-- Please Select Item --></option>
<?
$strSQL = "SELECT * FROM drug ORDER BY id ASC";
$objQuery = mysql_query($strSQL);
while($objResuut = mysql_fetch_array($objQuery))
{
if($strDefault == $objResuut["id"])
{
$sel = "selected";
}
else
{
$sel = "";
}
?>
<option value="<?=$objResuut["value"].$objResuut["value1"]; ?>" <?=$sel;?>>
<?=$objResuut["id"]." - ".$objResuut["name_med"]." - ".$objResuut["value"]." - ".$objResuut["value1"];?>
</option>
<?
}
?>
</select>
<table width="200" border="1">
<tr>
<td><div id='showdiv1'></div></td>
<td><div id='showdiv2'></div></td>
</tr>
</table>
<!--<input type="text" id='showinput'>
<input type="text" class='showclass'>
<input type="text" class='showclass'>-->
</body>
</html>