Let’s say I have a select with some option values
<select name="select">
<option value="item-one">Item one</option>
<option value="item-two">Item two</option>
</select>
<input type="number" name="quantity">
If I selected Item one, I want the input number to have a max allowed value of 3, otherwise if Item two if selected it would be 4.
I tried looping it using foreach loop but wont return the right result
2
Answers
You can use this
You cannot do that in PHP but with JavaScript you can.
I use an array where the index matches the selectedIndex of the select
I trigger on load and I also reduce if the select is changed
I added an input event handler too, because min/max only works with the spinners AND the submit event.
Alternative for my input test is to set and trigger custom validity on the input field