php - 通过文本框值将单选按钮设置为 true?

标签 php javascript

当我更改文本框中的值时,我需要选中单选按钮

radio button value 100.00rs                     input hidden array 10 clients     
radio button value 200.00 - 250.00rs            input hidden array 30 clients    
radio button value 250.00 - 300.00rs            input hidden array 50 clients    
radio button value 300.00 - 350.00rs            input hidden array 75 clients    
radio button value 350.00 - 400.00rs            input hidden array 100 clients    

这些值是通过 mysql-php foreach 循环获取的 当我使用 javascript onchange 函数更改文本框的值时,应根据该值选择单选按钮。 例如 如果我在文本框中输入 10,则应选择第一个单选按钮 否则,如果我输入 200-250 秒之间的值,则应选择单选按钮

function onChangeTest() {
var radio = document.getElementsByName("amt[1]") 
var qty2 = document.getElementsByName("max[]") 
var input = document.getElementById('ts').value;
    for(var i=0;i<radio.length;i++){
        if(input < qty2[i].value ){  // if input is < or between radio button value
        //document.getElementByName('amt[2]').checked = true;
        alert(radio[i].value + '\n' + qty2[i].value + '\n' +  input + '\n' + i) ; 
        }
    }

}

最佳答案

如果我理解你的问题,你是在问如何通过文本字段检查单选按钮。

基本上:

pseudocode
if text value == "true", then
    set radio button to true

这可以通过以下方式完成

HTML
<input type="text" id="txt">
<input type="radio" id="rad">

JAVASCRIPT
txt.onkeyup = function(){
    if(txt.value == 'true'){
        rad.checked = true;
    }else{
        rad.checked = false;
    }
}

See example

关于php - 通过文本框值将单选按钮设置为 true?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15304047/

相关文章:

javascript - 获取数据 javascript 并推送到数组 Cordova

javascript - 关闭 javascript 子窗口

php - 如何通过 PHP 处理 SELECT 1 的结果?

php - 从 PHP 页面 jQuery Iframe 传递 MYSQL 值

php - 从数据库删除文章减少/增加订单php

javascript - 使用 AngularJS 在 ngclick 上触发函数

javascript - 在搜索类型定义时何时使用环境?

php - 我可以同时提交两份表格吗?

php - 如何在PHP中使用SSL认证连接到WebSphere MQ队列

javascript - React JS - Firebase使用map方法在组件中显示数据