How do I limit character input length depending on options selected from dropdown?
Example: When OptionA-1 (value) is selected the input character limit will be only 2 digits (you can't write more than 2 digits) and When OptionB-1 (value) is selected input limit will be 5 digits (also you can't write more than 5 digits to the input box)? I've tried everything I could but I can't find any solution.
Is there a way to create jQuery or JavaScript Function and set maxLength of a number input? using ID of input box and id of options (like OptionA, OptionB, OptionC etc...). Thanks for reading and your help!
<select id="options" name="searchtype">
</optgroup>
<optgroup label="OptionA" >
<option id="OptionA" value="0/2">OptionA-1</option>
<option id="OptionA" value="0/4">OptionA-2</option>
<option id="OptionA" value="0/0">OptionA-3</option>
<option id="OptionA" value="0/1">OptionA-4</option>
<option id="OptionA" value="0/5">OptionA-5</option>
<option id="OptionA" value="0/3">OptionA-6</option>
</optgroup>
</optgroup>
<optgroup label="OptionB" >
<option id="OptionB" value="1/2">OptionB-1</option>
<option id="OptionB" value="1/4">OptionB-2</option>
<option id="OptionB" value="1/0">OptionB-3</option>
<option id="OptionB" value="1/1">OptionB-4</option>
<option id="OptionB" value="1/5">OptionB-5</option>
<option id="OptionB" value="1/3">OptionB-6</option>
</optgroup>
</select>
<input id="searchbox" type="number" size="40"></input>
Here is an example how to do that. I stored the maxLength values in a
data-maxattribute of every option. Maybe you could store them in the values, but I don't know, if you need the values for another reason.