Submit form dengan php tidak bisa karna penggunaan onchange dan location.replace

saya sedang membuat input data invoice, dimana ada 3 form yang akan saya simpan. no invoice, tanggal dan no po. no po ini diambil dari data po menggunakan select option, saya menggunakan onchange (onChange="pilih(this.value) untuk mengambil data po kemudian ditampilkan otomatis menggunakan tabel. dan menggunakan location.replace untuk menampilkan datanya sesuai dengan id. saat ini saya bingung untuk proses simpan semua data, yang biasanya submit otomatis karna form actionnya sudah sesuai, tapi saat diklik submit tidak mau ke submit.

1. tampilan input invoice

2. kode onchange pada select option

3. kode location.replace

4. kode form action untuk peroses semua data

avatar aihani
@aihani

3 Kontribusi 0 Poin

Dipost 4 tahun yang lalu

Tanggapan

bisa liat script insertnya ga?

kamu bingung cara insert semua datanya?

belum masuk ke script insertnya ka, form actionnya jadi mati ga bisa ke proses

maaf boleh sy lihat code full nya?

code fullnya di jawaban saya

2 Jawaban:

iya saya mau insert semua

avatar aihani
@aihani

3 Kontribusi 0 Poin

Dipost 4 tahun yang lalu

<script> function pilih(id){ location.replace("?module=form_invoice&id="+id); } </script> <!-- tampilan form add data --> <!-- Content Header (Page header) --> <section class="content-header"> <h1> <i class="fa fa-edit icon-title"></i> Input Data Invoice </h1> <ol class="breadcrumb"> <li><a href="?module=beranda"><i class="fa fa-home"></i> Beranda </a></li> <li><a href="?module=invoice"> Invoice </a></li> <li class="active"> Tambah </li> </ol> </section>

<!-- Main content --> <section class="content"> <div class="row"> <div class="col-md-12"> <div class="box box-primary"> <!-- form start -->

        &lt;div class=&quot;box-body&quot;&gt;
		&lt;form role=&quot;form&quot; class=&quot;form-horizontal&quot; action=&quot;modules/invoice/proses.php?act=insert&quot; method=&quot;POST&quot; name=&quot;form&quot;&gt;
          &lt;?php  
          // fungsi untuk membuat kode transaksi
          $query_id = mysqli_query($mysqli, &quot;SELECT RIGHT(no_invoice,8) as kode FROM tb_invoice
                                            ORDER BY no_invoice DESC LIMIT 1&quot;)
                                            or die(&#039;Ada kesalahan pada query tampil no_invoice : &#039;.mysqli_error($mysqli));

          $count = mysqli_num_rows($query_id);

          if ($count &lt;&gt; 0) {
              // mengambil data kode transaksi
              $data_id = mysqli_fetch_assoc($query_id);
              $kode    = $data_id[&#039;kode&#039;]+1;
          } else {
              $kode = 1;
          }

          // buat no_invoice
          $tahun          = date(&quot;Y&quot;);
          $buat_id        = str_pad($kode, 6, &quot;0&quot;, STR_PAD_LEFT);
          $no_invoice = &quot;INV-$tahun-$buat_id&quot;;
          ?&gt;

          &lt;div class=&quot;form-group&quot;&gt;
            &lt;label class=&quot;col-sm-2 control-label&quot;&gt;Kode Transaksi&lt;/label&gt;
            &lt;div class=&quot;col-sm-5&quot;&gt;
              &lt;input type=&quot;text&quot; class=&quot;form-control&quot; name=&quot;no_invoice&quot; value=&quot;&lt;?php echo $no_invoice; ?&gt;&quot; readonly required&gt;
            &lt;/div&gt;
          &lt;/div&gt;

          &lt;div class=&quot;form-group&quot;&gt;
            &lt;label class=&quot;col-sm-2 control-label&quot;&gt;Tanggal&lt;/label&gt;
            &lt;div class=&quot;col-sm-5&quot;&gt;
              &lt;input type=&quot;text&quot; class=&quot;form-control date-picker&quot; data-date-format=&quot;dd-mm-yyyy&quot; name=&quot;tanggal_invoice&quot; autocomplete=&quot;off&quot; value=&quot;&lt;?php echo date(&quot;d-m-Y&quot;); ?&gt;&quot; required&gt;
            &lt;/div&gt;
          &lt;/div&gt;
          &lt;hr&gt;
		  	
          &lt;div class=&quot;form-group&quot;&gt;
            &lt;label class=&quot;col-sm-2 control-label&quot;&gt;No PO&lt;/label&gt;
			&lt;div class=&quot;col-sm-5&quot;&gt;
              &lt;select class=&quot;chosen-select&quot; name=&quot;id_po&quot; id=&quot;id&quot; onChange=&quot;pilih(this.value)&quot; data-placeholder=&quot;-- Pilih No PO --&quot;required&gt;
               &lt;option value=&quot;&quot;&gt;&lt;/option&gt;
                &lt;?php
				  $id = isset($_GET[&#039;id&#039;]) ? $_GET[&#039;id&#039;] : null;
				  
                  $query = mysqli_query($mysqli, &quot;SELECT * FROM tb_po ORDER BY id_po ASC&quot;)
                                                        or die(&#039;Ada kesalahan pada query tampil data Po: &#039;.mysqli_error($mysqli));
                  while ($data= mysqli_fetch_array($query)) {?&gt;
					&lt;option value=&quot;&lt;?php echo $data[&quot;id_po&quot;]?&gt;&quot;&gt;&lt;?php echo $data[&quot;no_po&quot;]?&gt; &lt;/option&gt;
				&lt;?php
				}
                ?&gt;
				&lt;/select&gt;
          &lt;/div&gt;
          &lt;/div&gt;

		  &lt;table class=&quot;table table-bordered&quot; id=&quot;resultTable&quot; data-responsive=&quot;table&quot;&gt;
		&lt;thead bgcolor=&quot;eeeeee&quot; align=&quot;center&quot;&gt;
        &lt;tr&gt;
		&lt;th class=&quot;center&quot;&gt;No&lt;/th&gt;
		&lt;th class=&quot;center&quot;&gt;No PO&lt;/th&gt;
		&lt;th class=&quot;center&quot;&gt;Nama Customer&lt;/th&gt;
        &lt;th width=&#039;200px&#039;class=&quot;center&quot;&gt;Deksripsi Barang&lt;/th&gt;
        &lt;th class=&quot;center&quot;&gt;Qty&lt;/th&gt;
        &lt;th class=&quot;center&quot;&gt;Harga Satuan&lt;/th&gt;
        &lt;th class=&quot;center&quot;&gt;Total Harga&lt;/th&gt;
		&lt;tr&gt;
		&lt;/thead&gt;
		&lt;?php
			$query=mysqli_query($mysqli,&quot;SELECT tb_customer.kode_customer,tb_customer.nama_customer,tb_po.kode_customer,tb_po.no_po,detail_po.deskripsi_barang,detail_po.qty,detail_po.harga_satuan,detail_po.total_harga
										 FROM tb_po INNER JOIN detail_po on detail_po.id_po=tb_po.id_po
													INNER JOIN tb_customer on tb_customer.kode_customer=tb_po.kode_customer
										 WHERE tb_po.id_po=&#039;$id&#039;&quot;)
								or die(&#039;Ada kesalahan pada query tampil data: &#039;.mysqli_error($mysqli));	
			$no=1;
			while($data=mysqli_fetch_array($query)){
		?&gt;
        &lt;tbody&gt;
		&lt;tr&gt;
		&lt;td class=&quot;center&quot;&gt;&lt;?php echo $no++;?&gt;&lt;/td&gt;
		&lt;td class=&quot;center&quot;&gt;&lt;?php echo $data[&#039;no_po&#039;];?&gt;&lt;/td&gt;
		&lt;td class=&quot;center&quot;&gt;&lt;?php echo $data[&#039;nama_customer&#039;];?&gt;&lt;/td&gt;
		&lt;td class=&quot;center&quot; width=&#039;200px&#039;&gt;&lt;?php echo $data[&#039;deskripsi_barang&#039;];?&gt;&lt;/td&gt;
		&lt;td class=&quot;center&quot;&gt;&lt;?php echo $data[&#039;qty&#039;];?&gt;&lt;/td&gt;
		&lt;td class=&quot;right&quot;&gt;&lt;?php echo $data[&#039;harga_satuan&#039;];?&gt;&lt;/td&gt;
		&lt;td class=&quot;right&quot;&gt;&lt;?php echo $data[&#039;total_harga&#039;];?&gt;&lt;/td&gt;
		&lt;/tr&gt;
		&lt;?php
	}
		?&gt;
		&lt;tr&gt;
		&lt;th&gt; &lt;/th&gt;
		&lt;th&gt; &lt;/th&gt;
		&lt;th&gt; &lt;/th&gt;
		&lt;th&gt; &lt;/th&gt;
		&lt;th&gt; &lt;/th&gt;
			&lt;th&gt;&lt;strong style=&quot;font-size: 15px; color: #222222;&quot;&gt;TOTAL DPP:&lt;/strong&gt;
			&lt;th class=&quot;right&quot;&gt;&lt;strong style=&quot;font-size: 15px; color: #222222;&quot;&gt;Rp.
			&lt;?php
			function formatMoney($number, $fractional=false) {
				if ($fractional) {
					$number = sprintf(&#039;%.2f&#039;, $number);
				}
				while (true) { 
					$replaced = preg_replace(&#039;/(-?\d+)(\d\d\d)/&#039;, &#039;$1,$2&#039;, $number);
					if ($replaced != $number) {
						$number = $replaced;
					} else {
						break;
					}
				}
				return $number;
			}
			$query1 = mysqli_query($mysqli, &quot;SELECT sum(total_harga) FROM detail_po where detail_po.id_po=&#039;$id&#039;&quot;)
                or die(&#039;Ada kesalahan pada query tampil data po: &#039;.mysqli_error($mysqli));
			while ($data= mysqli_fetch_assoc($query1)) {
			
			$subtotal=$data[&#039;sum(total_harga)&#039;];
			echo formatMoney($subtotal, true);
			
			$ppn=($subtotal*10)/100;
			
			$sub_total=$subtotal+$ppn;
			}		
			?&gt;
			&lt;/strong&gt;
		&lt;/tr&gt;
		&lt;tr&gt;
		&lt;th&gt; &lt;/th&gt;
		&lt;th&gt; &lt;/th&gt;
		&lt;th&gt; &lt;/th&gt;
		&lt;th&gt; &lt;/th&gt;
		&lt;th&gt; &lt;/th&gt;
			&lt;th&gt;&lt;strong style=&quot;font-size: 15px; color: #222222;&quot;&gt;PPN 10%:&lt;/strong&gt;
			&lt;th class=&quot;right&quot;&gt;&lt;strong style=&quot;font-size: 15px; color: #222222;&quot;&gt;Rp.
			&lt;?php
			echo formatMoney($ppn, true);	
			?&gt;
			&lt;/strong&gt;
		&lt;/tr&gt;
		&lt;tr&gt;
		&lt;th&gt; &lt;/th&gt;
		&lt;th&gt; &lt;/th&gt;
		&lt;th&gt; &lt;/th&gt;
		&lt;th&gt; &lt;/th&gt;
		&lt;th&gt; &lt;/th&gt;
			&lt;th&gt;&lt;strong style=&quot;font-size: 15px; color: #222222;&quot;&gt;SUBTOTAL :&lt;/strong&gt;
			&lt;th class=&quot;right&quot;&gt;&lt;strong style=&quot;font-size: 15px; color: #222222;&quot;&gt;Rp.
			&lt;?php
			echo formatMoney($sub_total, true);		
			?&gt;
			&lt;/strong&gt;
		&lt;/tr&gt;
&lt;/tbody&gt;
        &lt;/table&gt;

	&lt;input type=&quot;hidden&quot; name=&quot;subtotal&quot; value=&quot;&lt;?php echo $subtotal; ?&gt;&quot;&gt;
	&lt;input type=&quot;hidden&quot; name=&quot;ppn&quot; value=&quot;&lt;?php echo $ppn; ?&gt;&quot;&gt;
	&lt;input type=&quot;hidden&quot; name=&quot;sub_total&quot; value=&quot;&lt;?php echo $sub_total; ?&gt;&quot;&gt;
	
          &lt;div class=&quot;form-group&quot;&gt;
            &lt;div class=&quot;col-sm-offset-2 col-sm-10&quot;&gt;
              &lt;input type=&quot;submit&quot; class=&quot;btn btn-primary btn-submit&quot; name=&quot;simpan&quot; value=&quot;Simpan&quot;&gt;
              &lt;a href=&quot;?module=invoice&quot; class=&quot;btn btn-default btn-reset&quot;&gt;Batal&lt;/a&gt;
            &lt;/div&gt;
       

        &lt;/div&gt;&lt;!-- /.box footer --&gt;
				&lt;/form&gt;
    &lt;/div&gt;&lt;!-- /.box --&gt;
  &lt;/div&gt;&lt;!--/.col --&gt;
&lt;/div&gt;   &lt;!-- /.row --&gt;
&lt;/div&gt;   &lt;!-- /.row --&gt;
&lt;/div&gt;   &lt;!-- /.row --&gt;

</section><!-- /.content -->

avatar aihani
@aihani

3 Kontribusi 0 Poin

Dipost 4 tahun yang lalu

Login untuk ikut Jawaban