skip to Main Content

According to the conditions of my project, I want to use the IF command inside the html body tag, the parameter of the IF condition is the tag being empty. I have to do this because the html code will change based on the condition. How can I write the condition to check the input tag null value.

    @if (checking value of office_id))
             <div>update code</div>
    @else
             <div>store code</div>
    @endif
    ...

  <div>
     <input id="office_id" class="myform-control">
  </div>
    

2

Answers


  1. You could use JavaScript or jQuery to listen for changes on the input field, and then show or hide different parts of your HTML based on the input value.

    <div id="updateCode" style="display: none;">update code</div>
    <div id="storeCode" style="display: none;">store code</div>
    
    <div>
        <input id="office_id" class="myform-control">
    </div>
    
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
    <script>
    $(document).ready(function(){
        $('#office_id').on('input', function() {
            var inputValue = $(this).val();
            if (inputValue) {
                $('#updateCode').show();
                $('#storeCode').hide();
            } else {
                $('#updateCode').hide();
                $('#storeCode').show();
            }
        });
    });
    
    Login or Signup to reply.
  2. You can use Livewire with blade here just use
    wire:model.lazy

    Read more about this :
    https://laravel-livewire.com/docs/2.x/properties

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search