Kaskus

Tech

gegehareAvatar border
TS
gegehare
[ASK] Javascript clear value error
gan ane kan punya JS kek gini , fungsinya buat nampilin beberapa element form yg tadinya di hidden pake CSS

PHP Code:
function toggle4(showHideDiv) {

  
       var 
ele document.getElementById(showHideDiv counter);
    
//var x = document.forms["form1"]["cuset"+counter+1];
    
       
if(ele.style.display == "block") {
    
              
ele.style.display "none";
  
     if (
counter >= 0){
    
     
counter--;
     
     }
     
     
       }

       else if(
ele.style.display == "none"){
    
             
ele.style.display "block";    
      
       }
    
 
       if(
counter == numBoxes) {
                
document.getElementById("toggleButton").style.display "none";
       }
    else{
    
document.getElementById("toggleButton").style.display "inline";
    }
    
 if(
counter == 0) {
                
document.getElementById("toggleButtonRemove").style.display "none";
       }
    else{
    
document.getElementById("toggleButtonRemove").style.display "inline";
    } 


trs HTML nya gini

PHP Code:
<tr>
        <
td>Jenis Cucian</td>
        <
td>:</td>
        <
td colspan="3">1. <select name="jeniscucian1" style="width:50">
          <
option>BedCover</option>
          <
option>Selimut</option>
          <
option>Gordyn</option>
          <
option>Sprei tebal</option>
          <
option>Jaket</option>
          <
option>Paket (diatas 7KG)</option>
        </
select>
        <
label for="textfield">
          <
input name="jecu1" type="text" id="jecu1" size="5" maxlength="5" value="0" class="classname" />
        
potong</label>
  <
input id="cuset1" name="cuset1" type="radio" value="cuci dan setrika" checked/> Cuci Setrika
  
  
<input id="cuset1" name="cuset1" type="radio" value="setrika" /> Setrika
  
<label class="harga">*Harga</label>
  </
td>
        <
td width="105"></td>
    </
tr>
    
    <
tr>
  
        <
td></td>
        <
td></td>
        <
td colspan="3"><div id="box1" style="display: none;">2. <select name="jeniscucian2" style="width:50">
          <
option>BedCover</option>
          <
option>Selimut</option>
          <
option>Gordyn</option>
          <
option>Sprei tebal</option>
          <
option>Jaket</option>
          <
option>Paket (diatas 7KG)</option>
        </
select>
        <
label for="textfield">
          <
input name="jecu2" type="text" id="jecu2" size="5" maxlength="5" value="0" class="classname" />
        
potong</label>
  <
input name="cuset2" id="cuset2" type="radio" value="cuci dan setrika" /> Cuci Setrika
  
  
<input name="cuset2" id="cuset2" type="radio" value="setrika" /> Setrika
  
<label class="harga">*Harga</label>
  </
div>
        </
td>
        <
td>
        </
td>
  
    </
tr>
    
    <
tr>
  
        <
td></td>
        <
td></td>
        <
td colspan="3"><div id="box2" style="display: none;">3. <select name="jeniscucian3" style="width:50">
          <
option>BedCover</option>
          <
option>Selimut</option>
          <
option>Gordyn</option>
          <
option>Sprei tebal</option>
          <
option>Jaket</option>
          <
option>Paket (diatas 7KG)</option>
        </
select>
        <
label for="textfield">
          <
input name="jecu3" type="text" id="jecu3" size="5" maxlength="5" value="0" class="classname" />
        
potong</label>
  <
input name="cuset3" id="cuset3" type="radio" value="cuci dan setrika" /> Cuci Setrika
  
  
<input name="cuset3" id="cuset3" type="radio" value="setrika" /> Setrika
  
<label class="harga">*Harga</label>
  </
div>
        </
td>
        <
td>
        </
td>
  
    </
tr


trs 2 tombol ,
tombol add buat menampilkan (onclick="counter++; toggle4('box');")
tombol remove buat menghide (onclick="toggle4('box');")

PHP Code:
<input id="toggleButton" type="button" value="ADD">
  <
input id="toggleButtonRemove" type="button" value="REMOVE"


itu kan tiap di klik tombol add
maka muncul element diantara
PHP Code:
<div id="box[nomor]" style="display: none;"

</
div


trs kalo ane mau nya pas klik tombol remove , input ini clear , soalnya nanti berpengaruh di post ke database nya , soalnya waktu di hide dia ga sekalian clear , jd nya ikut ke posting ke database

PHP Code:
<input name="cuset3" id="cuset3" type="radio" value="cuci dan setrika" /> Cuci Setrika
  
  
<input name="cuset3" id="cuset3" type="radio" value="setrika" /> Setrika 


ane udh tambahin

document.getElementById("cuset"+counter+1).checked=false;

buat clear element baris terakhir yg di hide

jd gini JS nya ,

PHP Code:
if(ele.style.display == "block") {
    
              
ele.style.display "none";
    
document.getElementById("cuset"+counter+1).checked=false;
  
     if (
counter >= 0){
         
counter--;
     
     } 


malah fungsi nya jd ada yg error tombol remove kdg malah jd add
mohon bantuanya gan , atau agan punya metode laen buat clear ?

thanks in advance
0
1K
5
GuestAvatar border
Komentar yang asik ya
Urutan
Terbaru
Terlama
GuestAvatar border
Komentar yang asik ya
Komunitas Pilihan