输入字段选择

时间:2019-02-08 10:55:41

标签: javascript php html forms event-handling

我在PHP / HTML中的输入/选择字段有问题。如果用户在输入字段中输入数字,则选择框应自动选择该值。我以为我可以用事件监听器onchange解决此问题,但我不确定如何。

update [UK_Telco_Pressure_2018Q3_2019-01-31 W2]
set [UK_Telco_Pressure_2018Q3_2019-01-31 W2].Video_Name=[UK_Telco_Pressure_2018Q3_2019-01-31 WEEK1] 
where [UK_Telco_Pressure_2018Q3_2019-01-31 WEEK1].Updated_Campaign=[UK_Telco_Pressure_2018Q3_2019-01-31 W2].Updated_Campaign

3 个答案:

答案 0 :(得分:0)

用onblur调用该事件。我确定它将起作用

我给你简单的例子


    <select name="" id="asd">
        <option value="ashir">ashir</option>
        <option value="haroon">haroon</option>
    </select>

    <input type="text" id="input_id" onblur="func()">

JS代码

function func(){
        var input_id = document.getElementById('input_id').value;
        document.getElementById('asd').value = input_id;
    }

答案 1 :(得分:0)

第一件事“ onchange”事件在HTML的文本字段中不可用,相反,您可以使用“ onkeyup”事件,例如:-

document.getElementById('number').addEventListener('keyup',(event) => {
    let num = parseInt(event.target.value);
    // write here the code to select the right option in drop down
});

答案 2 :(得分:0)

在codepen中尝试一下:

const  selectBoxField = document.getElementById('name')
const fieldNumber = document.getElementById('number')

fieldNumber.addEventListener('keyup', ({target}) => {
  selectBoxField.selectedIndex = target.value-1;
});
// variant with Id's
fieldNumber.addEventListener('keyup', ({target}) => {  
  const index = Array.from(selectBoxField).findIndex(option => option.id === target.value);
  selectBoxField.selectedIndex = index; 
});

在此处查看工作示例https://codepen.io/kurkov87/pen/daJBpa?editors=1111

相关问题