2016-11-08 4 views
3

Auswahl Dropdown-Wert nicht in der Lage, bestimmte divs.Hieris mein Code zu verstecken.Verbergen bestimmter divs bei der Auswahl Dropdown-Werte in coderigniter

Ausblick:

function showRequiredOption(cval) 
 
\t { 
 
\t \t if(cval=='interstate') 
 
\t \t { 
 
\t \t \t $('#cgst').hide(); 
 
\t \t \t $('#sgst').hide(); 
 
\t \t \t 
 
\t \t } 
 
\t \t else if(cval=='exemptedsales') 
 
\t \t { 
 
\t \t \t $('#cgst').hide(); 
 
\t \t \t $('#sgst').hide(); 
 
\t \t \t $('#igst').hide(); 
 
\t \t \t 
 
\t \t } 
 
\t \t else 
 
\t \t { 
 
\t \t \t $('#igst').hide(); 
 
\t \t \t $('#cgst').show(); 
 
\t \t \t $('#sgst').show(); 
 
\t \t \t 
 
\t \t } 
 
\t }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<div class="col-md-9 col-md-offset-2"> 
 
\t <div id="legend"> 
 
\t \t <legend class="">Profile Information</legend> 
 
\t </div> 
 
    <form role= action="<?php echo site_url();?>invoice/addinvoice" method="post" class="form-horizontal" id="location" method="post" accept-charset="utf-8"> \t \t 
 
\t \t <div class="form-group"> 
 
\t \t \t <label class="control-label col-sm-2 " for="user">User</label> 
 
\t \t \t <div class="col-sm-4 col-sm-offset-1"> 
 
\t \t \t \t <select id="user" name="user" onchange="showRequiredOption(this.value);"> 
 
\t \t \t \t \t <option value="employee">Local Sales</option> 
 
\t \t \t \t \t <option value="interstate">Inter state</option> 
 
\t \t \t \t \t <option value="freelancer">Stock transfers</option> 
 
\t \t \t \t \t <option value="exemptedsales">Exempted Sales</option> 
 
\t \t \t \t \t <option value="company">Zero Rated Sales</option> 
 
\t \t \t \t \t <option value="freelancer">Job Work</option> 
 
\t \t \t \t </select> 
 
\t \t \t </div> 
 
\t \t </div> \t \t 
 
\t \t <div class="form-group"> 
 
\t \t <label class="control-label col-sm-2 " for="hsn">Freight Charges</label> 
 
\t \t <div class="col-sm-4 col-sm-offset-1"> 
 
\t \t \t <input type="text" class="form-control" id="hsn" placeholder="Enter HSN Number" > 
 
\t \t </div> 
 
\t \t </div> 
 
\t \t 
 
\t \t <div class="form-group" id="igst"> 
 
\t \t <label class="control-label col-sm-2 " for="hsn">IGST 18%</label> 
 
\t \t <div class="col-sm-4 col-sm-offset-1"> 
 
\t \t \t <input type="text" class="form-control" id="hsn" placeholder="Enter HSN Number" > 
 
\t \t </div> 
 
\t \t </div> \t 
 
\t \t <div class="form-group" id="sgst"> 
 
\t \t <label class="control-label col-sm-2 " for="hsn">SGST 9%</label> 
 
\t \t <div class="col-sm-4 col-sm-offset-1"> 
 
\t \t \t <input type="text" class="form-control" id="sgst" placeholder="Enter HSN Number" > 
 
\t \t </div> 
 
\t \t </div> \t 
 
\t \t <div class="form-group" id="cgst"> 
 
\t \t <label class="control-label col-sm-2 " for="hsn">CGST 9%</label> 
 
\t \t <div class="col-sm-4 col-sm-offset-1"> 
 
\t \t \t <input type="text" class="form-control" id="cgst" placeholder="Enter HSN Number" > 
 
\t \t </div> 
 
\t \t </div> \t \t \t 
 
     <button id="submit" type="submit" class="btn" name="submit">Submit</button> 
 
    </form> 
 
    </div>

hier, wenn ich zwischenstaatlichen wählen, Umlagerungen in Drop-Down-CGST, SGST ausgeblendet werden soll und IGST angezeigt werden sollen.

Wenn ich Ausgenommene Verkäufe, Zero Rated Verkäufe, Arbeit im Dropdown-Menü IGST, CGST, SGST auswählen sollte ausgeblendet werden.

standardmäßig sollte es zeigen SGST und CGST

+0

@AndrewLi: schön zu wissen, aber es gab wenig-zu-keine PHP-Code in diesem Snippet, sicherlich nicht genug für das Snippet zu brechen. –

Antwort

3

den Raum Nehmen zwischen else if

Bedingungen: interstat or Stock Transfers CGST wählen, sollte SGST ausgeblendet werden und IGST angezeigt werden sollen.

Wählen Sie Exempted sales,Zero Rated sales,Job Work im Dropdown IGST, CGST, SGST sollte ausgeblendet werden.

function showRequiredOption(cval) 
 
{ 
 
\t if((cval=='interstate') || (cval == "stocktransfers")) 
 
\t { 
 
\t \t $('#cgst').hide(); 
 
\t \t $('#sgst').hide(); 
 
\t \t $('#igst').show(); 
 
\t } 
 
\t else if ((cval=='exemptedsales') || (cval=="zeroratedsales") ||(cval=="jobwork")) 
 
\t { 
 
\t \t $('#cgst').hide(); 
 
\t \t $('#sgst').hide(); 
 
\t \t $('#igst').hide(); 
 
\t \t 
 
\t } 
 
\t else 
 
\t { 
 
\t \t $('#igst').hide(); 
 
\t \t $('#cgst').show(); 
 
\t \t $('#sgst').show(); 
 
\t \t 
 
\t } 
 
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<div class="col-md-9 col-md-offset-2"> 
 
<div id="legend"> 
 
    <legend class="">Profile Information</legend> 
 
</div> 
 
<form role="form" action="<?php echo site_url();?>invoice/addinvoice" method="post" class="form-horizontal" id="location" method="post" accept-charset="utf-8">  
 
    <div class="form-group"> 
 
     <label class="control-label col-sm-2 " for="user">User</label> 
 
     <div class="col-sm-4 col-sm-offset-1"> 
 
      <select id="user" name="user" onchange="showRequiredOption(this.value)"> 
 
       <option value="employee">Local Sales</option> 
 
       <option value="interstate">Inter state</option> 
 
       <option value="stocktransfers">Stock transfers</option> 
 
       <option value="exemptedsales">Exempted Sales</option> 
 
       <option value="zeroratedcompany">Zero Rated Sales</option> 
 
       <option value="jobwork">Job Work</option> 
 
      </select> 
 
     </div> 
 
    </div>  
 
    <div class="form-group"> 
 
     <label class="control-label col-sm-2 " for="hsn">Freight Charges</label> 
 
     <div class="col-sm-4 col-sm-offset-1"> 
 
     <input type="text" class="form-control" id="hsn" placeholder="Enter HSN Number" > 
 
     </div> 
 
    </div> 
 

 
    <div class="form-group" id="igst" style="display:none;"> 
 
     <label class="control-label col-sm-2 " for="hsn">IGST 18%</label> 
 
     <div class="col-sm-4 col-sm-offset-1"> 
 
     <input type="text" class="form-control" id="hsn" placeholder="Enter HSN Number" > 
 
     </div> 
 
    </div> 
 
    <div class="form-group" id="sgst"> 
 
     <label class="control-label col-sm-2 " for="hsn">SGST 9%</label> 
 
     <div class="col-sm-4 col-sm-offset-1"> 
 
     <input type="text" class="form-control" id="sgst" placeholder="Enter HSN Number" > 
 
     </div> 
 
    </div> 
 
    <div class="form-group" id="cgst"> 
 
     <label class="control-label col-sm-2 " for="hsn">CGST 9%</label> 
 
     <div class="col-sm-4 col-sm-offset-1"> 
 
     <input type="text" class="form-control" id="cgst" placeholder="Enter HSN Number" > 
 
     </div> 
 
    </div>   
 
    <button id="submit" type="submit" class="btn" name="submit">Submit</button> 
 
</form> 
 
</div>

+0

'cval =" Freiberufler "' ---> 'cval ==" Freiberufler "' –

+0

@prasad es funktioniert nicht – user7047368

+0

bekommen ein Problem standardmäßig zeigt es igst sollte es nicht zeigen – user7047368

2

Dies ist nur ein einfaches Beispiel, wie man das erreichen kann. Ich hoffe, du wirst die Antwort finden.

$(function() { 
 
    $('.input').hide(); 
 
    $('#sample').change(function(){ 
 
     $('.input').hide(); 
 
     $('#' + $(this).val()).show(); 
 
    }); 
 
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<select name="dropdown" id="sample"> 
 
    <option value="cgst">CGST</option> 
 
    <option value="sgt">SGT</option> 
 
</select> 
 

 
<br /> 
 

 
<hr> 
 

 
<input id="cgst" type="text" class="input" placeholder="CGST"> 
 
<input id="sgt" type="text" class="input" placeholder="SGT">

1
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script> 
    <script> 
function showRequiredOption(cval) 
{ 
    alert(cval); 
    if(cval=='interstate') 
    { 
     $('#cgst').hide(); 
     $('#sgst').hide(); 
     $('#igst').show(); 
    } 
    else if(cval=='exemptedsales') 
    { 
     $('#cgst').hide(); 
     $('#sgst').hide(); 
     $('#igst').hide(); 

    } 
    else 
    { 
     $('#igst').hide(); 
     $('#cgst').show(); 
     $('#sgst').show(); 

    } 
} 
</script> 

vergessen haben, Link von jquery js Datei "https://code.jquery.com/jquery-3.1.1.min.js" hinzufügen. also hat es nicht funktioniert. Verwenden Sie diesen Code, es funktioniert

Verwandte Themen