|
 |
|
ค่าในlistbox ไม่มาคับช่วยดูหน่อยคับ มันมาแค่ไอดี แต่name มันไม่มาคับ |
|
 |
|
|
 |
 |
|
list menu มันส่งได้แค่ value ครับ
Code (PHP)
function submits(){
var id = document.getElementById('country_id').value;
var name = document.getElementById('country_id').text;
alert (document.getElementById('country_id').text);
alert (document.getElementById('country_name_th').text);
}
<select style="width:150px;" id="country_id" name="country_id">
<option value="">ประเทศ</option>
<?
$sql1 = "SELECT country_id,country_name_th,country_name_eng,status_id FROM country";
$qry1 = mysql_query($sql1);
while($row1 = mysql_fetch_array($qry1)){
?>
<option value="<?=$row1['country_id']?>"><?=$row1['country_name_th']?></option>
<? } ?>
</select>
<?
$sql2 = "SELECT country_name_th FROM country WHERE country_id = '$country_id' ";
$qry2 = mysql_query($sql2);
$n = mysql_fetch_array($qry2);
?>
<input type="hidden" name="country_name_th" id="country_name_th" value="<? echo $n['country_name_th'];?>">
<input style="width:25px; height:25px;" type="button" value="เพิ่ม" onclick="submits()"/>
|
 |
 |
 |
 |
Date :
2011-07-19 11:07:39 |
By :
avsqlz |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ใช้ javascript อ่านค่า text ใน list ด้วยครับ
จะได้เป็น
Code (PHP)
function submits(){
var id = document.getElementById('country_id').value;
var name = document.getElementById('country_id').options[document.getElementById('country_id').selectedIndex].text;
alert (name);
}
<select style="width:150px;" id="country_id" name="country_id">
<option value="">ประเทศ</option>
<?
$sql1 = "SELECT
country.country_id,
country.country_name_th,
country.country_name_eng,
country.status_id
FROM
country
";
$qry1 = mysql_query($sql1);
while($row1 = mysql_fetch_array($qry1)){
?>
<option value="<?=$row1[country_id]?>"><?=$row1[country_name_th]?></option>
<? } ?>
</select>
<input style="width:25px; height:25px;" type="button" value="เพิ่ม" onclick="submits()"/>
|
ประวัติการแก้ไข 2011-07-19 11:19:35
 |
 |
 |
 |
Date :
2011-07-19 11:18:30 |
By :
adaaugusta |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เมื่อกี๊อ่านคำถามผิด โทดทีครับ ตามข้างบนเลยครับ
|
ประวัติการแก้ไข 2011-07-19 11:25:04
 |
 |
 |
 |
Date :
2011-07-19 11:21:00 |
By :
tomrambo |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ได้แล้วคร๊าาบ ขอบคุณครับ
|
 |
 |
 |
 |
Date :
2011-07-19 11:22:19 |
By :
parakiss8 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
แล้วทีนี้ผมแก้ function เป็น
Code (PHP)
function submits(){
arr[i] = new Array();
arr[i][0] = document.getElementById('country_id').value;
arr[i][1] = document.getElementById('country_id').options[document.getElementById('country_id').selectedIndex].text;
i++;
show();
}
function show(){
var j = 0;
var temp = "";
while(j < arr.length){
temp += "<tr><td>"+arr[j][0]+"</td></tr>";
j++;
}
document.getElementById("panel").innerHTML=temp;
}
</script>
<table id="panel">
</table>
มันนิ่งเลยอะคับ
|
 |
 |
 |
 |
Date :
2011-07-19 11:30:36 |
By :
parakiss8 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ได้แล้วคับ
Code (PHP)
var arr = new Array();
var i = 0;
function submits(){
arr[i] = new Array();
arr[i][0] = document.getElementById('country_id').value;
arr[i][1] = document.getElementById('country_id').options[document.getElementById('country_id').selectedIndex].text;
i++;
show();
}
function show(){
var j = 0;
var temp = "";
while(j < arr.length){
temp += arr[j][1]+" <br /> ";
j++;
}
document.getElementById("panel").innerHTML=temp;
}
<select style="width:150px;" id="country_id" name="country_id">
<option value="">ประเทศ</option>
<?
$sql1 = "SELECT
country.country_id,
country.country_name_th,
country.country_name_eng,
country.status_id
FROM
country
";
$qry1 = mysql_query($sql1);
while($row1 = mysql_fetch_array($qry1)){
?>
<option value="<?=$row1[country_id]?>"><?=$row1[country_name_th]?></option>
<? } ?>
</select>
<input style="width:25px; height:25px;" type="button" value="เพิ่ม" onclick="submits()"/>

มันเกิดปัญหาคือข้อมูลมันซ้ำแล้วก็หากผมต้องการให้ลบได้จะต้องทำยังไงคับ
|
 |
 |
 |
 |
Date :
2011-07-19 12:12:00 |
By :
parakiss8 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 04
|