JSFiddle - React, Tailwind, and code Playground

HTML

<form id="example" name="example">
    <select id="sensor">
        <option value="Jval" data-foo="Jfoo">Joption</option>
        <option value="Kval" data-foo="Kfoo">Koption</option>
    </select>
    <br />
    <input type="text" value="" id="sensorText" />
</form>

JavaScript

var selectField = document.getElementById('sensor');
var textField = document.getElementById('sensorText');
var updateTextField = function() {
    textField.setAttribute(
        'value',
        selectField.options[selectField.selectedIndex].dataset.foo
    );
}

// Populate your text field when loading your page
updateTextField();

// Update your text field when an option is selected
selectField.addEventListener('change', updateTextField);