My javascript function only works when the page is fully loaded
P粉320361201
P粉320361201 2023-09-11 16:31:59
0
1
467

I want to disable the input text after the user clicks on another input tag with checkbox type,

The problem is that the date range input text is not disabled every time I click on the checkbox, can anyone help?

function myFunction() {
  document.getElementById("daterange").disabled = true;
}
<div class="item form-group">
  <label class="control-label col-md-3 col-sm-3 col-xs-12" for="email">Date <span class="required">*</span>
        </label>
  <div class="col-md-6 col-sm-6 col-xs-12">
    <input type="text" name="daterange" id="daterange" class="form-control date" placeholder="Choose multiple dates">
    <p style="color: white">
      <input type="checkbox" name="everyday" id="everyday" onclick="myFunction()" value="everyday" class="flat" /> Everyday
    </p>
  </div>
</div>

edit: I just realized that when the page is not fully loaded it works as I expected, but if the page is fully loaded there seems to be something that prevents the functionality from working

P粉320361201
P粉320361201

reply all(1)
P粉667649253

Maybe you can try using alpineJS

in laravel
<div class="item form-group">
  <label class="control-label col-md-3 col-sm-3 col-xs-12" for="email">Date <span class="required">*</span>
        </label>
  <div x-data="{ inputDisabled: false }"  class="col-md-6 col-sm-6 col-xs-12">
    <input x-bind:disabled="inputDisabled"  type="text" name="daterange" id="daterange" class="form-control date" placeholder="Choose multiple dates">
    <p style="color: white">
      <input x-on:click="inputDisabled = true" type="checkbox" name="everyday" id="everyday"  value="everyday" class="flat" /> Everyday
    </p>
  </div>
</div>

If you use laravel brezze, alpine JS is already included. We can easily manipulate our DOM without writing a lot of JS code. Just write in inline HTML

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template