在codeigniter

时间:2016-11-08 04:52:33

标签: javascript php jquery html codeigniter

选择下拉值无法隐藏特定div.Hereis我的代码。

查看:

function showRequiredOption(cval)
	{
		if(cval=='interstate')
		{
			$('#cgst').hide();
			$('#sgst').hide();
			
		}
		else if(cval=='exemptedsales')
		{
			$('#cgst').hide();
			$('#sgst').hide();
			$('#igst').hide();
			
		}
		else
		{
			$('#igst').hide();
			$('#cgst').show();
			$('#sgst').show();
			
		}
	}
<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= 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="freelancer">Stock transfers</option>
					<option value="exemptedsales">Exempted Sales</option>
					<option value="company">Zero Rated Sales</option>
					<option value="freelancer">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">
		  <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>

如果我在下拉列表中选择州际,股票转移cgst,则应隐藏sgst并显示igst。

如果我选择豁免销售,零评级销售,下拉工作,IGST,CGST,SGST应该被隐藏。

默认显示应显示sgst和cgst

3 个答案:

答案 0 :(得分:3)

else if

之间应用空格

条件:    选择interstat or Stock Transfers cgst,应隐藏sgst并显示igst。

在下拉列表中选择Exempted sales,Zero Rated sales,Job Work IGST,CGST,SGST应该被隐藏。

function showRequiredOption(cval)
{
	if((cval=='interstate') || (cval == "stocktransfers"))
	{
		$('#cgst').hide();
		$('#sgst').hide();
		$('#igst').show();
	}
	else if ((cval=='exemptedsales') || (cval=="zeroratedsales") ||(cval=="jobwork"))
	{
		$('#cgst').hide();
		$('#sgst').hide();
		$('#igst').hide();
		
	}
	else
	{
		$('#igst').hide();
		$('#cgst').show();
		$('#sgst').show();
		
	}
}
<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>

答案 1 :(得分:2)

这只是一个关于如何实现这一目标的简单示例。希望你能通过这个找到答案。

&#13;
&#13;
$(function() {
  $('.input').hide();
    $('#sample').change(function(){
        $('.input').hide();
        $('#' + $(this).val()).show();
    });
});
&#13;
<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">
&#13;
&#13;
&#13;

答案 2 :(得分: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>

你忘了添加jquery js文件“https://code.jquery.com/jquery-3.1.1.min.js”的链接。所以它不起作用。使用此代码它正在工作