alexa-tracking
Selamat Guest, Agan dapat mencoba tampilan baru KASKUS Masih Kangen Tampilan Sebelumnya
Kategori
Kategori
Home / FORUM / All / Tech / ... / Programmer Forum /
[ASK] Cara menyisipkan variabel php kedalam fungsi alert di javascript
1024
1024
KASKUS
51
244
https://www.kaskus.co.id/thread/539bcc9231e2e667798b460e/ask-cara-menyisipkan-variabel-php-kedalam-fungsi-alert-di-javascript

[ASK] Cara menyisipkan variabel php kedalam fungsi alert di javascript

Gan ane mau tanya..

Jadi gini gan kasusnya:
tanggal Awal ___________ tanggal Akhir______________
jam Awal ___________ jam Akhir______________

Waktu Pengerjaan --> 0day - 0hour - 0menit - 0detik

#note:
1. tanggal akhir, jam akhir, dan waktu pengerjaan akan muncul hasilnya saat "Submit" di klik
2. Waktu Pengerjaan didapat dari (tanggal akhir & jam akhir dikurangi tanggal awal & jam awal). tampil secara otomatis.
3. Default value Waktu Pengerjaan diisi dengan 0day - 0hour - 0menit - 0detik.

Nah yg jd pertanyaannya adalah kenapa saat ane klik submit, value dari Waktu Pengerjaan yg masuk ke database itu malah yang isinya 0day - 0hour - 0menit - 0detik.. Harusnya kan yg masuk ke database itu valueNya yg hasil pengurangan td (tanggal akhir & jam akhir dikurangi tanggal awal & jam awal) ??????

Klo misalnya si variabel php yg menyimpan value Waktu Pengerjaan itu disisipkan ke fungsi alert di javascript, kira-kira bs ga gan ?? jd saat query update, langsung ditembak lg dgn query update yg skemanya td via javascript alert.

*Mohon Pencerahannya gan, maap ane msh newbie emoticon-Sorry
*Mohon bimbingannya emoticon-Sorry
Urutan Terlama
Quote:


Kode yg sudah dikerjakan mana?
klo mnurut ane yg masih newbie agan convert smua data ke satu satuan menit atau apalah.. trus dijumlah, btw ane cman tau coding java, coding php gk tau emoticon-Cape d... (S)
Quote:


nih gan kodingnya :

Tabel_support.php :
Code:
<? session_start();
if(!$_SESSION['level']==2) {
?>
[removed]
alert("Maaf, akses anda ditolak !!! Dimohon untuk login terlebih dahulu ");
location='../index.php';
[removed]
<? } else {?>
<? include"../module/konek.php";?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Support Table</title>
</head>
<link rel="stylesheet" type="text/css" href="../css/style.css" />
<body>
<div align="center"><font face="Rockwell Condensed" color="#553F00" size="+2">IT-Support WorkOrder List</font></div>
<hr>
<br />
<form method="post" name="src" action="" >
<table width="612" cellspacing="0" cellpadding="0" align="center">
<tr>
<th width="230" align="center">Cari Berdasarkan Serial Komplain</th>
<th width="491"><input type="text" name="txtcari" maxlength="12" />    
<input name="cari" type="submit" value="Apply Filter" />
<input name="tam" type="submit" value="Reset Filter" /></th>
</tr>

</table>
</form>
<br /><br />
<?
include"../module/konek.php";

echo "<table border='0' width='950' align='center'>
<tr>
<th> No</th>
<th> Serial Komplain</th>
<th> User</th>
<th> Cabang</th>
<th> Serial CPU</th>
<th> Status</th>
<th> View</th>
</tr>";
if(isset($_POST['cari'])){
$txtcari=$_POST['txtcari'];
$_SESSION['txt']=$txtcari;
$final=$_SESSION['txt'];
}
if(isset($_POST['tam'])){
unset($final);
}
$url=$_GET['un'];
$batas = 10;
$halaman = $_GET['halaman'];
if(empty($halaman)){
$posisi = 0;
$halaman = 1;
}
else{
$posisi = ($halaman-1) * $batas;
}

$rs = mysql_query ("SELECT * FROM t_its,t_cabang,t_action WHERE t_its.id_cab=t_cabang.id_cab AND t_its.id_act=t_action.id_act AND t_its.serial_comp LIKE '%$txtcari%' ORDER BY serial_comp asc LIMIT $posisi,$batas");

$no = $posisi+1;
while ( $hasil = mysql_fetch_array($rs)){
$id = $hasil['serial_comp'];
$idd = substr($id,1,15);
if(($no % 2)==0){
$warna="#CCCCCC";
}
else{
$warna="#FFF";
}

echo "<tr bgcolor=$warna>";
echo "<td>" . $no . "</td>";
echo "<td>" . $hasil['serial_comp'] . "</td>";
echo "<td>" . $hasil['user'] . "</td>";
echo "<td>" . $hasil['cabang'] . "</td>";
echo "<td>" . $hasil['serial_cpu'] . "</td>";
echo "<td><div class=kelip>" . $hasil['action'] . "</div></td>";
echo "<td>    <a >Detail</a></td>";
echo "</tr>";
$no++;
}
echo "</table>";
echo"<p> </p>";



$tampil2 = mysql_query("SELECT * FROM t_its WHERE serial_comp LIKE '%$txtcari%'");
$jmldata = mysql_num_rows($tampil2);
$jmlhal = ceil($jmldata/$batas);
echo "<div class=paging>";
if($halaman > 1){
$prev=$halaman-1;
echo "<span class=prevnext><a ><< Prev</a></span> ";
}
else{
echo "<span class=disabled><< Prev</span> ";
}

// Tampilkan link halaman 1,2,3 ...
for($i=1;$i<=$jmlhal;$i++)
if ($i != $halaman){

echo " <a >$i</a> ";
}
else{
echo " <span class=current>$i</span> ";
}

// Link kehalaman berikutnya (Next)
if($halaman < $jmlhal){
$next=$halaman+1;
echo "<span class=prevnext><a >Next >></a></span>";
}
else{
echo "<span class=disabled>Next >></span>";
}
echo "</div>";
echo "<p align=center>Total : <b>$jmldata</b> User</p>";
}
?>

</div>

</body>
</html>


det_worksup.php
Code:
<? session_start();
if(!$_SESSION['level']==2) {
?>
[removed]
alert("Maaf, akses anda ditolak !!! Dimohon untuk login terlebih dahulu ");
location='../index.php';
[removed]
<? } else {?>
<? include"../module/konek.php";?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<link rel="stylesheet" type="text/css" href="../css/style.css" />
<body>
<?

$dbs=$_GET['kdds'];
if($dbs) {

$query="SELECT * FROM t_its,t_cabang,t_action,t_operator WHERE t_its.id_cab=t_cabang.id_cab AND t_its.id_act=t_action.id_act AND t_its.id_op=t_operator.id_op AND t_its.serial_comp LIKE '%$dbs'";
$sql=mysql_query($query);
$result=mysql_fetch_array ($sql);
date_default_timezone_set("Asia/Jakarta");
$jam = date('H:i:s');
$day = date("Y-m-d");
$kdr=$result['serial_comp'];
$nmr=$result['tgl'];
$tyk=$result['jam'];
$stat=$result['user'];
$hrga=$result['cabang'];
$krga=$result['id_cab'];
$ket=$result['keluhan'];
$ktr=$result['ket'];
$keg=$result['serial_cpu'];
$vsr=$result['action'];
$ksr=$result['id_act'];
$vgh=$result['jam_act'];
$drt=$result['tgl_act'];
$aew=$result['jamf_act'];
$xsd=$result['tglf_act'];
$rty=$result['wkt_tanggap'];
$rtz=$result['wkt_pengerjaan'];
$sfl=$result['staff_lapor'];
$ido=$result['nama'];
$selisih = strtotime($drt) - strtotime($nmr);
$hari = $selisih/(60*60*24)."d";

$tanggal1="$drt $vgh";
$tanggal2="$nmr $tyk";
//untuk waktu tanggap
//hitung hari

$selisih=strtotime($tanggal1)-strtotime($tanggal2);

$hasil=$selisih/(60*60*24);

$bulathari=floor($hasil);



//hitung jam

$sisajam=$selisih%(60*60*24);

$hour=$sisajam/3600;

$bulatjam=floor($hour);



//hitung menit

$sisamenit=$sisajam%3600;

$minute=$sisamenit/60;

$bulatmenit=floor($minute);



//hitung detik

$sisadetik=$sisamenit%60;

$bulatdetik=floor($sisadetik);

$tanggal3="$xsd $aew";
$tanggal4="$drt $vgh";
//untuk waktu pengerjaan
//hitung hari

$selisih2=strtotime($tanggal3)-strtotime($tanggal4);

$hasil2=$selisih2/(60*60*24);

$bulathari2=floor($hasil2);



//hitung jam

$sisajam2=$selisih2%(60*60*24);

$hour2=$sisajam2/3600;

$bulatjam2=floor($hour2);



//hitung menit

$sisamenit2=$sisajam2%3600;

$minute2=$sisamenit2/60;

$bulatmenit2=floor($minute2);



//hitung detik

$sisadetik2=$sisamenit2%60;

$bulatdetik2=floor($sisadetik2);

if($drt=="0000-00-00" && $vgh=="00:00:00" ) {
$cmc .="0 d - 0 h - 0 m - 0 s";
} else {
$cmc .="$bulathari d - $bulatjam h - $bulatmenit m - $bulatdetik s";
}

if($xsd=="0000-00-00" && $aew=="00:00:00" ) {
$cmd .="0 d - 0 h - 0 m - 0 s";
} else {
$cmd .="$bulathari2 d - $bulatjam2 h - $bulatmenit2 m - $bulatdetik2 s";
}

if($drt=="0000-00-00" && $vgh=="00:00:00" && $ktr=="" && $ksr="5" ) {
$text="<textarea name=ket cols=54 rows=5 readonly=yes class=disable></textarea>";
$textbox="<input type=text name=wrt readonly=yes class=disable></textarea>";
$dis=" disabled = disabled";
$dsb=" disabled = disabled";
}else{
$text="<textarea name=ket cols=40 rows=5 ></textarea>";
$textbox="<input type=text name=wrt2 value='$ktr' readonly=yes></textarea>";
$disa=" disabled = disabled";
$dsb=" disabled = disabled";
}



if($ksr=="4" or $ksr=="3"){

$disabl=" disabled = disabled";
$disab=" disabled = disabled";

$text="<textarea name=ket cols=54 rows=5 readonly=yes class=disable></textarea>";
$textbox="<input type=text name=wrt value='$ktr' readonly=yes></textarea>";
$dis=" disabled = disabled";
} elseif($ksr=="2"){
$textbox="<input type=text name=wrt readonly=yes class=disable></textarea>";
$disab=" disabled = disabled";
} elseif($ksr=="1"){
$textbox="<input type=text name=wrt readonly=yes class=disable></textarea>";
}
if(empty($ktr) or ($rty!="0 d - 0 h - 0 m - 0 s" && $rtz!="0 d - 0 h - 0 m - 0 s" )){
$dsbb .="<input type='submit' name='sls' value='<< Back To View Complaint ' disabled = disabled";
} else {
$dsbb .="<input type='submit' name='sls' value='<< Back To View Complaint'";
}

echo"<table align='center' border='0' width='75%'>
<tr>
<td colspan='3'><h3 align='center'>View and change Action</h3></td>
</tr>

<tr>
<td align='right'>Serial Komplain</td>
<td>:</td>
<td><input type='text' name='kod' value='$kdr' readonly='yes' /></td>

<tr>
<td align='right'>Staff Pelapor</td>
<td>:</td>
<td><input type='text' name='sfl' value='$sfl' readonly='yes'/></td>

</tr>
<tr>
<td align='right'>User Komplain</td>
<td>:</td>
<td><input type='text' name='hrg' value='$stat' readonly='yes'/></td>

</tr>
<tr>
<td align='right'>Cabang Komplain</td>
<td>:</td>
<td><input type='text' name='ty_k' value='$hrga' readonly='yes' /><input type='hidden' name='sta' value='$stat'/></td>

</tr>
<tr>
<td align='right'>Komplain</td>
<td>:</td>
<td><input type='text' name='dr' value='$ket' size='70' readonly='yes'/></td>

</tr>
<tr>
<td align='right'>Pemecahan Masalah</td>
<td>:</td>
<td>$textbox</td>

</tr>
<tr>
<td align='right'>Serial CPU</td>
<td>:</td>
<td><input type='text' name='hrg' readonly='yes' value='$keg' size='25'/></td>
</tr>
<tr>
<td align='right'>Status</td>
<td>:</td>
<td><input type='text' name='stat_act' value='$vsr' readonly='yes' /></td>
</tr>
<tr>
<td align='right'>Staff Aksi</td>
<td>:</td>
<td><input type='text' name='staf_ak' value='$ido' readonly='yes' /></td>
</tr>
<table align='center' width='85%'>
<th>
<td align='right'>Waktu Komplain
<input type='text' name='fcl' value='$nmr' size='8' readonly='yes' /><input type='text' name='ty_k' value='$tyk' size='7' readonly='yes' /></td>

</th>
<th>
<td align='right'>Waktu Aksi
<input type='text' name='drt' value='$drt' size='8' readonly='yes' />
<input type='text' name='sact' value='$vgh' size='7' readonly='yes' /></td>
</th>
<th>
<td align='right'>Waktu Tanggap

<input type='text' name='sact' readonly='yes' value='$cmc' size='22' /></td>
</th></table>
<table align='center' width='75%'>
<th>
<td align='right'>Mulai Aksi
<input type='text' name='drt' value='$drt' size='8' readonly='yes' />
<input type='text' name='sact' value='$vgh' size='7' readonly='yes' /></td>
</th>
<th>
<td align='right'>Selesai Aksi
<input type='text' name='juy' value='$xsd' size='8' readonly='yes' />
<input type='text' name='lop' value='$aew' size='7' readonly='yes' /></td></th>
<th>
<td align='right'>Waktu Pengerjaan

<input type='text' name='zact' readonly='yes' value='$cmd' size='22' /></td>
</th></table>";

$que=mysql_query("SELECT * FROM t_action");
$has=mysql_fetch_array($que);
$gt=$has['id_act'];
$gt2=$has['action'];
echo"<table align='center' width='75%'><form action='../module/pros_act.php' method='post'><tr align='center'><td><input type='submit' name='wip' value='Walk in Progress'$disa></td></tr>";

echo"<tr><td><input type='hidden' name='kod' value='$kdr' readonly='yes' /><input type='hidden' name='jm' value='$tyk' /><input type='hidden' name='tgl' value='$nmr' /><input type='hidden' name='usr' value='$stat'/><input type='hidden' name='cbn' value='$krga' /><input type='hidden' name='klhn' value='$ket' size='70'/><input type='hidden' name='scpu' value='$keg' size='25'/><input type='hidden' value='$kdr' name='hidd' /><input type='hidden' value='$jam' name='wtc' /><input type='hidden' value='$day' name='day' /><input type='hidden' value='0000-00-00' name='dmy' /><input type='hidden' value='00-00-00' name='his' />
<input type='hidden' value='1' name='sts' /></td></tr>";

echo"</form></table>";

echo"<table align='center' width='75%'><form action='../module/pros_act3.php' method='post'><tr align='center'><td><input type='submit' name='pnd' value='Pending'$disab></td></tr>";

echo"<tr><td><input type='hidden' name='kod' value='$kdr' readonly='yes' /><input type='hidden' name='jm' value='$tyk' /><input type='hidden' name='tgl' value='$nmr' /><input type='hidden' name='usr' value='$stat'/><input type='hidden' name='cbn' value='$krga' /><input type='hidden' name='klhn' value='$ket' size='70'/><input type='hidden' name='scpu' value='$keg' size='25'/><input type='hidden' value='$kdr' name='hidd' /><input type='hidden' value='$ksr' name='ksr' /><input type='hidden' value='0000-00-00' name='dmy' /><input type='hidden' value='00-00-00' name='his' /><input type='hidden' value='2' name='sts3' /></td></tr>";

echo"</form></table>";
echo"<table align='center' width='75%'><form action='../module/pros_act4.php' method='post'><tr align='center'><td><input type='submit' name='cls' value='Close'$disabl></td></tr>";

echo"<tr><td><input type='hidden' name='kod' value='$kdr' readonly='yes' /><input type='hidden' name='jm' value='$tyk' /><input type='hidden' name='tgl' value='$nmr' /><input type='hidden' name='usr' value='$stat'/><input type='hidden' name='cbn' value='$krga' /><input type='hidden' name='klhn' value='$ket' size='70'/><input type='hidden' name='scpu' value='$keg' size='25'/><input type='hidden' value='$kdr' name='hidd' /><input type='hidden' value='$jam' name='wtc' /><input type='hidden' value='$day' name='day' /><input type='hidden' value='$ksr' name='ksr' /><input type='hidden' value='3' name='sts4' /></td></tr>";

echo"</form></table>";
echo"<table align='center' width='75%'><form action='../module/pros_act2.php' method='post'><tr align='center'></tr>";

echo"<tr><td><input type='hidden' name='kod' value='$kdr' readonly='yes' /><input type='hidden' name='jm' value='$tyk' /><input type='hidden' name='tgl' value='$nmr' /><input type='hidden' name='usr' value='$stat'/><input type='hidden' name='cbn' value='$krga' /><input type='hidden' name='klhn' value='$ket' size='70'/><input type='hidden' name='scpu' value='$keg' size='25'/><input type='hidden' value='$kdr' name='hidd' /><input type='hidden' value='$jam' name='wtc' /><input type='hidden' value='$day' name='day' /><input type='hidden' value='$ksr' name='ksr' />
<input type='hidden' value='4' name='sts2' />
<input type='text' name='tanggap' value='$cmc'>
<input type='hidden' name='tgl_pkj1' value='$xsd'>
<input type='hidden' name='jam_pkj1' value='$aew'>
<input type='hidden' name='tgl_pkj2' value='$drt'>
<input type='hidden' name='jam_pkj2' value='$vgh'>
<input type='text' name='pengerjaan' value='$cmd'><td align='center'>Pemecahan Masalah</td><td>:</td><td>$text</td></td><tr><td></td><td></td><td></td><td><input type='submit' name='dn' value='Done'$dis></td></tr></tr>";

echo"</form></table>";
echo"<form action='' method='post'>
<table align='center'>
<td colspan='3'><input type='hidden' name='ert' value='$cmc'><input type='hidden' name='ery' value='$cmd'><input type='hidden' value='$kdr' name='hi' />$dsbb</td>
</table></form>";

$qu=mysql_query("SELECT * FROM t_operator WHERE id_op='$_SESSION[userid]'");
$hs=mysql_fetch_array($qu);
$idp=$hs['id_op'];
if(isset($_POST['sls'])){
$a=$_POST['ert'];
$b=$_POST['ery'];
$c=$_POST['hi'];
$que = "UPDATE t_its SET wkt_tanggap='$a',wkt_pengerjaan='$b' where serial_comp='$c'";
$tl=mysql_query($que);
if ($tl) {
?>
[removed]
alert("Terimaksih anda telah bekerja dengan baik.");
location='../support/form.php?page=show_b';
[removed]
<?
}}}}
?>

</body>
</html>

pros_act2.php :
Code:
<? session_start();?>
<?php
include"konek.php";
$qu=mysql_query("SELECT * FROM t_operator WHERE id_op='$_SESSION[userid]'");
$hs=mysql_fetch_array($qu);
$idp=$hs['id_op'];

if (isset($_POST['dn'])) {
$kod=$_POST['kod'];
$tgl=$_POST['tgl'];
$jm=$_POST['jm'];
$usr=$_POST['usr'];
$cbn=$_POST['cbn'];
$klhn=$_POST['klhn'];
$scpu=$_POST['scpu'];
$dat=$_POST['hidd'];
$wtc=$_POST['wtc'];
$day=$_POST['day'];
$sts2=$_POST['sts2'];
$ket=$_POST['ket'];
$tanggap=$_POST['tanggap'];
$pengerjaan=$_POST['pengerjaan'];
$tgl_pkj1=$_POST['tgl_pkj1'];
$jam_pkj1=$_POST['jam_pkj1'];
$tgl_pkj2=$_POST['tgl_pkj2'];
$jam_pkj2=$_POST['jam_pkj2'];



$tanggal3="$tgl_pkj1 $jam_pkj1";
$tanggal4="$tgl_pkj2 $jam_pkj2";
//untuk waktu pengerjaan
//hitung hari

$selisih2=strtotime($tanggal3)-strtotime($tanggal4);

$hasil2=$selisih2/(60*60*24);

$bulathari2=floor($hasil2);



//hitung jam

$sisajam2=$selisih2%(60*60*24);

$hour2=$sisajam2/3600;

$bulatjam2=floor($hour2);



//hitung menit

$sisamenit2=$sisajam2%3600;

$minute2=$sisamenit2/60;

$bulatmenit2=floor($minute2);



//hitung detik

$sisadetik2=$sisamenit2%60;

$bulatdetik2=floor($sisadetik2);

$gabung="$bulathari2 d - $bulatjam2 h - $bulatmenit2 m - $bulatdetik2 s";

$que = "UPDATE t_its SET serial_comp='$kod',tgl='$tgl',jam='$jm',user='$usr',serial_cpu='$scpu',keluhan='$klhn',ket='$ket',id_cab='$cbn',id_act='$sts2',jamf_act='$wtc',tglf_act='$day',id_op='$idp',wkt_tanggap='$tanggap',wkt_pengerjaan='$gabung' where serial_comp='$dat'";
$tl=mysql_query($que);

if ($tl) {
?>
[removed]
alert("Komplain ini telah berhasil diselesaikan.");
location='../support/form.php?page=ls';
[removed]
<?
$text="<textarea name=ket cols=54 rows=5 readonly=yes class=disable></textarea>";
$dis=" disabled = disabled";
}}
?>


#Jadi pada intinya ane tuh pengen memasukkan value Waktu_Pengerjaan yg hasil pengurangan antara (Selesai aksi dan Mulai aksi).... nah masalah yg terjadi skrg adalah malah value dafault yg masuk ke databasenya (default value= 0d 0h 0m 0s)
Diubah oleh ayout.vertigo
Agan sistah yg udah master ,tolong bantuin ane untuk masalah ini emoticon-Berduka (S)emoticon-Berduka (S)emoticon-Berduka (S)
Variable php ke alert javascript?

Code:

<?php
$variable = "Hello world";
?>

< script >
alert('<?php echo $variable; ?>');
< / script>

<!-- scriptnya ke- sensor emoticon-Big Grin -->



Mestinya begini sih bisa emoticon-Big Grin
Diubah oleh rusakdalam


×
GDP Network
Copyright © 2018, Kaskus Networks, PT Darta Media Indonesia.
Ikuti KASKUS di