|
|
|
พอมีตัวอย่าง onchage ค่าจาก radio button ไปเป็น listbox บ้างไหมครับ |
|
|
|
|
|
|
|
แบบ ติ๊ก อันแรก ให้ listbox โขว์ ค่าของ if ใน function
ติ๊กอันสอง ให้ listbox โชว์ ค่าของ else อ่ะครับ
Code (PHP)
<? include ('config.php'); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script type="text/javascript">
function swapShow()
{
var radioObj = document.getElementById("item1");
if(radioObj.checked == true)
document.getElementById("displayArea").innerHTML = "<?php
$q = mysql_query ("SELECT * FROM position WHERE positions_value = 1");
while ($r=mysql_fetch_array($q)){
echo $r['name_position']." ";
} ?>";
else
document.getElementById("displayArea").innerHTML = "<?php
$q = mysql_query ("SELECT * FROM position WHERE positions_value = 2");
while ($r=mysql_fetch_array($q)){
echo $r['name_position']." ";
} ?>";
}
</script>
</head>
<body>
<p><? echo $r['name_position']." "; ?>
<input type="radio" name="item" id="item1" value="1" onchange="swapShow()" />
<input type="radio" name="item" id="item2" value="2" onchange="swapShow()" />
</p>
<p>
<label for="select"></label>
<select name="select" id="select">
</select>
</p>
<div id="displayArea"></div>
</body>
</html>
|
ประวัติการแก้ไข 2014-08-04 19:26:09 2014-08-04 19:28:23
|
|
|
|
Date :
2014-08-04 19:25:45 |
By :
jpong7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
อะจึ้ย javascript ผสม php
Code (PHP)
<? include ('config.php'); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script type="text/javascript">
function swapShow(t)
{
var radioObj = document.getElementById("item1");
if(t)
document.getElementById("displayArea").innerHTML = "<?php
$q = mysql_query ("SELECT * FROM position WHERE positions_value = 1");
while ($r=mysql_fetch_array($q)){
echo $r['name_position']." ";
} ?>";
else
document.getElementById("displayArea").innerHTML = "<?php
$q = mysql_query ("SELECT * FROM position WHERE positions_value = 2");
while ($r=mysql_fetch_array($q)){
echo $r['name_position']." ";
} ?>";
}
</script>
</head>
<body>
<p><? echo $r['name_position']." "; ?>
<input type="radio" name="item" id="item1" value="1" onclick="swapShow(true)" />
<input type="radio" name="item" id="item2" value="2" onclick="swapShow(false)" />
</p>
<p>
<label for="select"></label>
<select name="select" id="select">
</select>
</p>
<div id="displayArea"></div>
</body>
</html>
ไม่รู้ทำได้หรือเปล่า ไม่ได้ลอง
ปล. redio จะใช้ onclick นะครับ เพาะทุกครั้งที่คลิก จะเป็น จริงเสมอ
|
ประวัติการแก้ไข 2014-08-04 20:06:37 2014-08-04 20:07:51 2014-08-04 20:09:54
|
|
|
|
Date :
2014-08-04 20:05:17 |
By :
Chaidhanan |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Date :
2014-08-04 20:36:19 |
By :
jpong7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code (PHP)
<? include ('config.php');
$option_1=''; $option_2=''; $jsvar_1=''; $jsvar_2='';
$rs = mysql_query ("SELECT * FROM position order by positions_value");
while ($ro=mysql_fetch_assoc($rs)){
$nm=$ro['name_position'];
if($ro['positions_value']=='1'){
$option_1 .= "<option value='$nm' >$nm</option>";
$jsvar_1 .= "position_1[]='$nm';\n";
}elseif($ro['positions_value']=='2'){
$option_2 .= "<option value='$nm' >$nm</option>";
$jsvar_2 .= "position_2[]='$nm';\n";
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script type="text/javascript">
var position_1 = Array();
<?php echo $jsvar_1; ?>
var position_2 = Array();
<?php echo $jsvar_2; ?>
function swapShow(t){
var c, i=0, op;
var slc=document.getElementById("select");
slc.optiions.length = 0; // Clear option;
if(t){
c=position_1.length;
for( i ; i<c; i++){
op = document.createElement('option');
op.value=position_1[i];
op.text=position_1[i];
slc.add(op);
}
}else{
c=position_2.length;
for( i ; i<c; i++){
op = document.createElement('option');
op.value=position_2[i];
op.text=position_2[i];
slc.add(op);
}
}
}
</script>
</head>
<body>
<input type="radio" name="item" id="item1" value="1" onclick="swapShow(true)" checked /> Postion 1<br />
<input type="radio" name="item" id="item2" value="2" onclick="swapShow(false)" /> Position 2<br />
<select name="select" id="select">
<?php echo $option_1; ?>
</select>
</body>
</html>
ปรับเปลี่ยนตำแหน่งเอาเองนะครับ ผมเขียนตามผมถนัด
|
|
|
|
|
Date :
2014-08-04 21:10:52 |
By :
Chaidhanan |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 00
|