Reseller Domain Murah dan termurah di Indonesia? ya di ResellerCamp.
         
 

Forum PHP Indonesia

 
Advanced Search
   
 
Home Register FAQ Memberlist Usergroups  
 
 

Forum PHP Indonesia Forum Index PHP Help Check box dalam tabel
Display posts from previous:   
      All times are GMT + 7 Hours  

Check box dalam tabel

Post new topic  Reply to topic Goto page 1, 2  Next

Tue Sep 07, 2010 09:42
Author Message
baldhead77
PHPuser
PHPuser


Joined: 03 Sep 2010
Posts: 27

Post subject: Check box dalam tabel Reply with quote

mas brow smua...
ane minta tolong neh...
gmn ya caranya buat tabel di web dengan check box??
klo di check,maka kolom disampingnya jadi edit-able..

contohnya kyk gini gan...
ada 1 tabel dengan 3 kolom..
kolom JML, CHECK, SUM

*kasus 1
barang dikirim 50 (kolom JML diisi 50)...jika sampe di gudang 50..maka kolom CHECK dikosongkan..dan SUM otomatis jadi 50

*kasus 2
barang dikirim 100 (kolom JML diisi 100)..jika sampe di gudang 95..maka kolom CHECK di centang...dan SUM bisa di edit manual (diisi 95)...dengan demikian keliatan kekurangannya bro...

#jika di centang maka di tabel database, akan bernilai 1..dan kalau kosong akan bernilai 0

yah,mungkin seperti itulah kasusya brow..
klo ada yg bisa tolong dibantu ya
thanks bgt brow2 skalian

I Love U Helppp!!
 
View user's profile Send private message Yahoo Messenger
      Back To Top  

Tue Sep 07, 2010 12:59
Author Message
mas boy
PHP Programmer
PHP Programmer


Joined: 20 Aug 2009
Posts: 123

Post subject: Reply with quote

coba pakai HTML DOM dan Javascript, seharusnya bisa menyelesaikan masalah tersebut.

atau yang mudah begini saja, di bagian sum menggunakan textbox yang defaulnya dibuat readonly, jadi gak bisa kebaca... nah di bagian CHECK dibuatkan event yang berfungsi jika CHECK dalam posisi checked, maka ubah readonly pada sum menjadi false, sehingga ia bisa di edit secara manual. begitu dah garis besarnya.
_________________
Menerima pembuatan aplikasi Web dengan PHP-MySQL dengan fitur web 2.0

Kunjungi blog saya di http://catatankuliahku2008.wordpress.com/
 
View user's profile Send private message Send e-mail Yahoo Messenger
      Back To Top  

Tue Sep 07, 2010 16:37
Author Message
baldhead77
PHPuser
PHPuser


Joined: 03 Sep 2010
Posts: 27

Post subject: Reply with quote

boleh tau g brow??
eventnya kyk gmn script nya..
masih newbie soalnya... hail Big Smile
 
View user's profile Send private message Yahoo Messenger
      Back To Top  

Tue Sep 07, 2010 19:37
Author Message
mas boy
PHP Programmer
PHP Programmer


Joined: 20 Aug 2009
Posts: 123

Post subject: Reply with quote

saya coba buat filenya, dan jalan di firefox ini kode htmlnya :

Code:
<?php <html
<
head
<
title>Checkbox Event Handler</title
<
style type="text/css"
#myGroup {visibility:hidden} 
</style
<
script type="text/javascript"
function 
toggle(chkboxx) { 
    if (
chkbox.checked){         
        
document.getElementById(x).type="hidden"
        
document.getElementById("nilai_jml").innerHTML=document.getElementById("jml").value;
    } else {        
        
document.getElementById(x).type="text";         
        }


function 
sum(x) {
        
document.getElementById("sum").value x;
        
    }
</script> 
</head> 
<body> 
<table>
<th>JML</th><th>CHECK</th><th>SUM</th>
<tr>
    <td><input type="text" value="" name="jml" id="jml" onchange="sum(this.value)"></td>
    <td><input type="checkbox" name="cek" id="cek" onclick="toggle(this, 'sum')" />check</td>
    <td><input type="text" value="" name="sum" id="sum"><span id="nilai_jml"> </span></td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
</tr>
</table>

</body> 
</html> ?>


Namun untuk produksi script diatas belum sempurna, masih diperlukan beberapa penyesuaian untuk berbagai kemungkinan kondisi inputan. Tetapi secara garis besar se[erti diatas prinsipnya.

Silahkan dicoba, moga membantu.
_________________
Menerima pembuatan aplikasi Web dengan PHP-MySQL dengan fitur web 2.0

Kunjungi blog saya di http://catatankuliahku2008.wordpress.com/
 
View user's profile Send private message Send e-mail Yahoo Messenger
      Back To Top  

Tue Sep 07, 2010 19:43
Author Message
mas boy
PHP Programmer
PHP Programmer


Joined: 20 Aug 2009
Posts: 123

Post subject: Reply with quote

oh ya saya lupa untuk ceckboxnya dalam kondisi ter-checked, input text untul sum saya ubah typenya menjadi hidden, sehingga valunya tidak ditampilkan maka untuk menampilkan valunya saya gunakan span disebelahnya, tapi jika dalam kondisi unchecked maka type inputan sum saya ganti menjadi text sehingga valuenya ditampilkan, harusnya span disebelahnya saya kosongkan isinya (innerHTML=""), tapi belum saya lakukan di bagian fungsinya. silahkan bereksperimen dengan fungsi-fungsi diatas.
_________________
Menerima pembuatan aplikasi Web dengan PHP-MySQL dengan fitur web 2.0

Kunjungi blog saya di http://catatankuliahku2008.wordpress.com/
 
View user's profile Send private message Send e-mail Yahoo Messenger
      Back To Top  

Wed Sep 08, 2010 09:08
Author Message
baldhead77
PHPuser
PHPuser


Joined: 03 Sep 2010
Posts: 27

Post subject: Reply with quote

waaah...
makasih banyak mas brow...
ane coba dulu...klo misalnya ada problem.nanti gw posting lg...
wish me luck...

thankie mas boy...
hail Salute!
 
View user's profile Send private message Yahoo Messenger
      Back To Top  

Wed Sep 08, 2010 13:49
Author Message
baldhead77
PHPuser
PHPuser


Joined: 03 Sep 2010
Posts: 27

Post subject: Reply with quote

mas brow boy...
gw coba koding diatas...

gw ada masalah...
ini gw sertain koding gw..coba di cek
(mungkin baiknya mas boy copykan,dan lihat hasilnya)
*note = nama database :'stokbarang' (MYsql)
nama tabel : 'inventory'

ini koding 'coba.php'

Code:
<?php <html
<
head
<
title>Checkbox Event Handler</title
<
style type="text/css"
#myGroup {visibility:hidden} 
</style
<
script type="text/javascript"
function 
toggle(chkboxx) { 
    if (
chkbox.checked){         
        
document.getElementById(x).type="hidden"
        
document.getElementById("nilai_jml").innerHTML=document.getElementById("jml").value;
    } else {        
        
document.getElementById(x).type="text";         
        }


function 
sum(x) {
        
document.getElementById("sum").value x;
        
    }
</script>

</head> 

<body>
<?php 

        
include "konfig.php";
            
$sql ="select * from inventory";
            
$resultmysql_query($sql);
            
$numrows=mysql_num_rows($result);
            echo
                
"<table border width=50%>
                <tr>
                <td>Kode</td>
                <td>Nama</td>
                <td>QTY</td>
                <td>CHECK</td>
                <td>SUM</td>
                </tr>"
;
            while(
$row=mysql_fetch_array($result))
            {
            echo 
                
"<tr>
                <td>$row[0] </td>
                <td>$row[1] </td>
                <td><input type=text value=0 name=jml id=jml onchange=sum(this.value)></td>
                <td><input type=checkbox name=cek id=cek onclick=toggle(this, sum) />check</td>
                <td><input type=text value=0 name=sum id=sum><span id=nilai_jml> </span></td>
            </tr>"
;
        
            }            
            echo 
"</table>"


?>
</body> 
</html> ?>



masalahnya :
1. Tombol checkbox tidak berfungsi (setelah dicek kolom SUM tetap aktif
2.Jika mengedit baris ke 2, ke 3, dst...data SUM yang terubah tetap pada baris 1

o iya, ini saya sertakan jg koding buat "konfig.php" daripada buat lagi kan...
Big Smile

Code:
<?php $host="localhost";
$user="root";
$password="";
$database "stokbarang";

$res=mysql_connect($host,$user,$password);
if(!
$res)
    echo 
"Koneksi ke database gagal";
$hasil=mysql_select_db($database);
if(!
$hasil)
    echo 
"Database gagal dibuka"?>



Tolong ya mas udah merepotkan...
soalnya asli gw g bisa tdr,kepikiran mulu...
thnks...
 
View user's profile Send private message Yahoo Messenger
      Back To Top  

Fri Sep 10, 2010 20:39
Author Message
mas boy
PHP Programmer
PHP Programmer


Joined: 20 Aug 2009
Posts: 123

Post subject: Reply with quote

1. ganti bagian ini
Code:
<?php <script type="text/javascript"
function 
toggle(chkboxx) { 
    if (
chkbox.checked){         
        
document.getElementById(x).type="hidden"
        
document.getElementById("nilai_jml").innerHTML=document.getElementById("jml").value;
    } else {        
        
document.getElementById(x).type="text";         
        }


function 
sum(x) {
        
document.getElementById("sum").value x;
        
    }
</script> ?>


dengan ini
Code:
<?php <script type="text/javascript"
function 
toggle(chkbox,x,i) { 
    if (!
chkbox.checked){         
        
document.getElementById(x).type="hidden"
        
document.getElementById("nilai_jml"+i).innerHTML=document.getElementById("jml"+i).value;
    
document.getElementById("nilai_jml"+i).style.display="block";
    } else {        
        
document.getElementById(x).type="text";
    
document.getElementById("nilai_jml"+i).style.display="none";         
        }


function 
sum(x,i) {
        
document.getElementById("sum"+i).value x;
    
document.getElementById("nilai_jml"+i).innerHTML=document.getElementById("jml"+i).value;
        
    }
</script> ?>


2. kemudian ganti
Code:
<?php while($row=mysql_fetch_array($result))
            {
            echo 
                
"<tr>
                <td>$row[0] </td>
                <td>$row[1] </td>
                <td><input type=text value=0 name=jml id=jml onchange=sum(this.value)></td>
                <td><input type=checkbox name=cek id=cek onclick=toggle(this, sum) />check</td>
                <td><input type=text value=0 name=sum id=sum><span id=nilai_jml> </span></td>
            </tr>"
;
        
            } 
?>

menjadi

Code:
<?php $i=1;
while(
$row=mysql_fetch_array($result))
            {
            echo 
                
"<tr>
                <td>$i </td>
                <td>$i </td>
                <td><input type='text' value=0 name='jml' id='jml$i' onchange=sum(this.value,'$i')></td>
                <td><input type='checkbox' name='cek' id='cek$i' onclick=toggle(this,'sum$i','$i') />check</td>
                <td><input type='hidden' value=0 name='sum' id='sum$i'><span id='nilai_jml$i'></span></td>
            </tr>"
;
        
$i++;
        
            } 
?>


harap diingat, penting untuk kode html yang digenerate dari php seperti inputan pada form untuk tetap memberikan tanda petik, apalagi pada nama dan id masing-masing inputan.

Cekidot...

Cool Man Drink
_________________
Menerima pembuatan aplikasi Web dengan PHP-MySQL dengan fitur web 2.0

Kunjungi blog saya di http://catatankuliahku2008.wordpress.com/
 
View user's profile Send private message Send e-mail Yahoo Messenger
      Back To Top  

Fri Sep 10, 2010 20:44
Author Message
mas boy
PHP Programmer
PHP Programmer


Joined: 20 Aug 2009
Posts: 123

Post subject: Reply with quote

ini kode yang saya buat dengan memodifikasi kode yang bro berikan. tapi saya modif dengan menggunakan perulangan for dan tanpa database, tetapi secara fungsi sudah bisa mengakomodasi kebutuhan bro. ini saya gunakan untuk testing di localhost sya saja, barangkali bisa dijadikan referensi :

Code:
<?php <html
<
head
<
title>Checkbox Event Handler</title
<
style type="text/css"
#myGroup {visibility:hidden} 
</style
<
script type="text/javascript"
function 
toggle(chkbox,x,i) { 
    if (!
chkbox.checked){         
        
document.getElementById(x).type="hidden"
        
document.getElementById("nilai_jml"+i).innerHTML=document.getElementById("jml"+i).value;
    
document.getElementById("nilai_jml"+i).style.display="block";
    } else {        
        
document.getElementById(x).type="text";
    
document.getElementById("nilai_jml"+i).style.display="none";         
        }


function 
sum(x,i) {
        
document.getElementById("sum"+i).value x;
    
document.getElementById("nilai_jml"+i).innerHTML=document.getElementById("jml"+i).value;
        
    }
</script>

</head> 

<body>
<?php 

       
/* include "konfig.php";
            $sql ="select * from inventory";
            $result= mysql_query($sql);
            $numrows=mysql_num_rows($result);
       */
       
echo
                
"<table border width=50%>
                <tr>
                <td>Kode</td>
                <td>Nama</td>
                <td>QTY</td>
                <td>CHECK</td>
                <td>SUM</td>
                </tr>"
;
        
//    while($row=mysql_fetch_array($result))
          
for ($i=1$i<=5$i++)
      {
            echo 
                
"<tr>
                <td>$i </td>
                <td>$i </td>
                <td><input type=text value=0 name=jml id='jml$i' onchange=sum(this.value,'$i')></td>
                <td><input type=checkbox name=cek id='cek$i' onclick=toggle(this,'sum$i','$i') />check</td>
                <td><input type='hidden' value=0 name=sum id='sum$i'><span id='nilai_jml$i'></span></td>
            </tr>"
;
        
            }            
            echo 
"</table>"


?>
</body> 
</html> ?>

_________________
Menerima pembuatan aplikasi Web dengan PHP-MySQL dengan fitur web 2.0

Kunjungi blog saya di http://catatankuliahku2008.wordpress.com/
 
View user's profile Send private message Send e-mail Yahoo Messenger
      Back To Top  

Fri Sep 10, 2010 21:03
Author Message
mas boy
PHP Programmer
PHP Programmer


Joined: 20 Aug 2009
Posts: 123

Post subject: Reply with quote

ini kode yang saya buat dengan memodifikasi kode yang bro berikan. tapi saya modif dengan menggunakan perulangan for dan tanpa database, tetapi secara fungsi sudah bisa mengakomodasi kebutuhan bro. ini saya gunakan untuk testing di localhost sya saja, barangkali bisa dijadikan referensi :

Code:
<?php <html
<
head
<
title>Checkbox Event Handler</title
<
style type="text/css"
#myGroup {visibility:hidden} 
</style
<
script type="text/javascript"
function 
toggle(chkbox,x,i) { 
    if (!
chkbox.checked){         
        
document.getElementById(x).type="hidden"
        
document.getElementById("nilai_jml"+i).innerHTML=document.getElementById("jml"+i).value;
    
document.getElementById("nilai_jml"+i).style.display="block";
    } else {        
        
document.getElementById(x).type="text";
    
document.getElementById("nilai_jml"+i).style.display="none";         
        }


function 
sum(x,i) {
        
document.getElementById("sum"+i).value x;
    
document.getElementById("nilai_jml"+i).innerHTML=document.getElementById("jml"+i).value;
        
    }
</script>

</head> 

<body>
<?php 

       
/* include "konfig.php";
            $sql ="select * from inventory";
            $result= mysql_query($sql);
            $numrows=mysql_num_rows($result);
       */
       
echo
                
"<table border width=50%>
                <tr>
                <td>Kode</td>
                <td>Nama</td>
                <td>QTY</td>
                <td>CHECK</td>
                <td>SUM</td>
                </tr>"
;
        
//    while($row=mysql_fetch_array($result))
          
for ($i=1$i<=5$i++)
      {
            echo 
                
"<tr>
                <td>$i </td>
                <td>$i </td>
                <td><input type=text value=0 name=jml id='jml$i' onchange=sum(this.value,'$i')></td>
                <td><input type=checkbox name=cek id='cek$i' onclick=toggle(this,'sum$i','$i') />check</td>
                <td><input type='hidden' value=0 name=sum id='sum$i'><span id='nilai_jml$i'></span></td>
            </tr>"
;
        
            }            
            echo 
"</table>"


?>
</body> 
</html> ?>

_________________
Menerima pembuatan aplikasi Web dengan PHP-MySQL dengan fitur web 2.0

Kunjungi blog saya di http://catatankuliahku2008.wordpress.com/
 
View user's profile Send private message Send e-mail Yahoo Messenger
      Back To Top  

Mon Sep 13, 2010 10:34
Author Message
baldhead77
PHPuser
PHPuser


Joined: 03 Sep 2010
Posts: 27

Post subject: Reply with quote

wah mantap mas brow boy...
codingnya anyar euy...

hail

sejauh ini masalah gw teratasi dengan baik...
thanks bgt bro...
jika ada masalah lagi, nanti gw konsultasiin lg
Weks


MINAL AIDZIN WAL FAIDZIN brow...
keep ur good work
 
View user's profile Send private message Yahoo Messenger
      Back To Top  

Mon Sep 13, 2010 14:13
Author Message
baldhead77
PHPuser
PHPuser


Joined: 03 Sep 2010
Posts: 27

Post subject: Reply with quote

mas brow boy..
semua script sudah implementasikan dengan database dan berjalan dgn baik...
data dari database sudah bisa ditampilkan dan diedit melalui web..

nah,timbul masalah baru...
gw rada bingung gmn caranya nyimpan nilai dari masing2 row ke tabel di database...
tapi gk semua nilai dari row tersebut yg akan diambil...
hanya nilai QTY,Check dan SUM saja yg diambil
soalnya gw coba,tapi tabel di database tidak terupdate...
tolong bantuannya mas brow boy... Helppp!!
 
View user's profile Send private message Yahoo Messenger
      Back To Top  

Mon Sep 13, 2010 14:20
Author Message
baldhead77
PHPuser
PHPuser


Joined: 03 Sep 2010
Posts: 27

Post subject: Reply with quote

o iya lupa...
yg jadi parameter penyamanya adalah Kode(web) dan kode(mysql)
thanks bro
 
View user's profile Send private message Yahoo Messenger
      Back To Top  

Thu Sep 16, 2010 06:21
Author Message
mas boy
PHP Programmer
PHP Programmer


Joined: 20 Aug 2009
Posts: 123

Post subject: Reply with quote

Kalo untuk mengambil data dari form dan memasukkannya ke database bukannya sama aja dengan aplikasi php lainnya??? tinggal kamu cari aja name dari masing-masing inputan, terus kamu parsing data yang dikirimkan ke file php. Jika data inputan dari form bisa diparsing/ di dapatkan di file itu, kemudian tinggal dimasukkan ke database aja.
_________________
Menerima pembuatan aplikasi Web dengan PHP-MySQL dengan fitur web 2.0

Kunjungi blog saya di http://catatankuliahku2008.wordpress.com/
 
View user's profile Send private message Send e-mail Yahoo Messenger
      Back To Top  

Thu Sep 16, 2010 07:12
Author Message
baldhead77
PHPuser
PHPuser


Joined: 03 Sep 2010
Posts: 27

Post subject: Reply with quote

sep mas...
sudah teratasi dgn baik...
MISSION 1 ACCOMPLISHED

sekarang ada masalah baru neh mas boy..
tolong check thread saya yang lain
disini mas...

http://www.forumphp.web.id/phpforum_7361_cara_mengecek_data_dari_form_ke_database.html

soalnya solusi yg mas kasih tokcer2..
siapa tau buat yang satu ini jg bisa Big Smile

tolong ya mas boy
 
View user's profile Send private message Yahoo Messenger
      Back To Top  
Post new topic  Reply to topic Goto page 1, 2  Next

 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


      Back To Top  

Page 1 of 2
Goto page 1, 2  Next
Jump to:  
Powered by phpBB © 2001, 2002 phpBB Group
Toko Kaos Couple | Avalanche style by What Is Real © 2004 | Toko Baju Butik Online | Cara Pedia | Busana Baju Muslim