JSFiddle - React, Tailwind, and code Playground

by Norlihazmey Ghazali

HTML

<input size="50" name="productname" id="product" type="text">
<select name="platform" id="platformid">
    <option value="">select</option>
    <option value="samsung">Samsubng</option>
    <option value="alcatel">Alcatel</option>
</select>

JavaScript

$("#product").on("change keyup paste", function () {
    var valuefound = '';
    $("#platformid option").each(function (i) {
        if ($(this).text().substring(0, 2).toLowerCase() == $("#product").val().substring(0, 2).toLowerCase()) {
            valuefound = $(this).val();
        }
    });
    $('option:selected', 'select[name="platformid"]').removeAttr('selected');
    $('#platformid option[value="' + valuefound + '"]').prop('selected', true);
})