I want to get output based on text input and select input, the value of strength will be determined by nvalue and type(select)
my current code:
function findStrength() {
var n = document.getElementById('nvalue');
if ($(".select-box option[value='clay']").attr('selected') && $(n.value == '30')) {
document.getElementById('soil_strength').value = 'HARD';
}
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input type="text" id="nvalue" name="nvalue" min="0" max="50" required />
<select class="select-box" name="soil_type" id="soil_type2">
<option value="" disabled selected hidden>Type</option>
<option value="clay">CLAY</option>
<option value="silt">SILT</option>
<option value="sand">SAND</option>
<option value="gravel">GRAVEL</option>
</select>
<input type="text" id="soil_strength" name="soil_strength" placeholder="Strength" />
2
Answers
You should not mix jQuery and DOM access. Here I delegate from form and any change to the fields will update the strength
Also you had typos in the max and required attributes
Lastly why not use a number field?
jQuery version
You can use jQuery more effectively.