-1

i have a select box that have two item (enable , disable) and three input

i want when the user select enable, each input be enabled and add Required Attribute to them.

And vice versa if select disable, each input be disabled and remove Required Attribute from them

can you help me

Mojtaba Delshad
  • 107
  • 1
  • 7
  • 1
    What have you tried so far? Please include a [mcve]. Also, see jQuery's [`.prop`](https://api.jquery.com/prop/) and [`.attr`](https://api.jquery.com/attr/) methods. – tshimkus May 03 '19 at 21:47
  • 2
    Possible duplicate of [jQuery add required to input fields](https://stackoverflow.com/questions/19166685/jquery-add-required-to-input-fields) – tshimkus May 03 '19 at 21:47
  • Try it yourself first. Post when you encounter an issue. Don't peek at this until you've tried it yourself (https://jsfiddle.net/1b6ns24j/). I know I shouldn't do that, but I'll be offline all weekend, and just wanted to help if you do end up trying it. Seriously, though, don't peek until you've tried it - you'll learn better that way. –  May 03 '19 at 21:51

1 Answers1

0

Add your inputs:

<input class=“my_input”></input>
<input class=“my_input”></input>
<input class=“my_input”></input>

Create disable and enable functions:

function disable() {
    $(“.my_input”).css(“pointer-events”, “none”)
}

function enable() {
    $(“.my_input”).css(“pointer-events”, “auto”)
}

Call those functions when and as needed.

Cybernetic
  • 12,628
  • 16
  • 93
  • 132