// JQuery script
<script>
$(function(){
$('.select-change').click(function(){
????
//将来自conld_class的textbox文本放在dropdown1下拉列表中会是什么!!
});
});
</script>
现在是PHP和HTML代码
<?PHP
connection...blah blah
while($record=sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC)){
$recordx = $record['x'];
$recordy = $record['y'];
$recordz = $record['z'];
}
?>
<input type="text" class="con_name_class" id="<? php somefunction_which_echos_out_a_text ?>" value="<? php
SAMEfunction_which_echos_out_a_text ?>" />
<input class = "select-change" type="button" id="<? php echo $recordx; ?>" value = "<? php echo $recordx; ?>" /><br>
<? PHP
}
function xyz(){ // I am calling it some where!!
connection...blah blah
echo "<select name = "dropdown1" id="dropdown1">";
echo "<option value="NULL">Select one</option>";
while($rec=sqlsrv_fetch_array($stmtxyz, SQLSRV_FETCH_ASSOC)){
echo "<option value='".$rec['con_code']."')>".$rec['con_name']."</option>";
}
</select>
}
?>
如何将文本框的文本映射到dropdown1并选择它?
答案 0 :(得分:2)
你可能喜欢
$(function() {
$("#textboxID").on("change",function(){
$("#selectBoxID").val($(this).val());
//Set the option from dropdown list by textbox's value
})
});
这是plunker
干杯!
答案 1 :(得分:0)
我正在修改NLN的代码。您可以在名称中指定特定部分,例如&#34; textbox _&#34;
<input type="text" class="con_name_class" id="textbox_<? php somefunction_which_echos_out_a_text ?>" value="<? php SAMEfunction_which_echos_out_a_text ?>" />
然后使用此脚本
$(function() {
$(input[id^="textbox_"]).on("change",function(){
$("#selectBoxID").val($(this).val());
//Set the option from dropdown list by textbox's value
})
});
答案 2 :(得分:0)
我用javascript函数做了..不是jquery ...因为我的文本框ID问题。在文本框的onClick上调用以下函数并传递参数。谢谢!
下面 -
function xyz(par){
var dd1= document.getElementbyId('dropdown1');
var opts = dd1.options.length;
for (var i =0; i<opts; i++){
if(document.getElementbyId('dropdown1').options[i].value == par){
getElementbyId('dropdown1').selectedIndex = i;
break;
}
}
}