2012-08-27 112 views
0

我想将文本框的值设置为我的下拉框第一次尝试.....我希望每当我的文本框的值应该改变时它应该获得下拉的值并在下拉菜单中显示框。从文本框中获取值并设置下拉框

我想要的任何值在我的文本框来从tablelist应该在我的下拉框中的默认值显示...

请帮助。

我尝试这样做:

$("#editdevicetype").wijcombobox({ 
    data : datasources, 
    showTrigger : true, 
    changed:function(e, data) { 
     dtype =data.selectedItem.value; 
     $('#deviceType1').val(dtype); 

     //document.getElementById("editdevicetype").value=dtype; 
     dttype =data.selectedItem.value; 
     $('#editdevicetype').val(dttype); 
     $('#editdevicetype').val($('#deviceType1').val()); 
    } 
}); 

我的表编号: currentCellChanging:功能(即参数){

$("#devicelist").wijgrid(
{ 
    allowSorting: true, 
allowColSizing: true, 

dtype=data[selRow].DeviceType; 
               document.getElementById("deviceType1").value=dtype; 
              //dttype=data.label; 
              document.getElementById("editdevicetype").value=dtype.replaceByValue(/[^>]+$/, dtype); 
+0

什么是您的文本框和下拉框? – Calvein

+0

@calvein:#editdevicetype这是下拉和#deviceType1这是文本框.....我选择下拉值时,文本框的值会自动更改.....但我想反向选项时,我的文本框的值将更改下拉框应显示文本框的值也...... – Tina

+0

什么是'tablelist'? “tablelist”中的值如何被设置为文本框?如果您自己的js代码正在这样做,那么您可以在设置该值后简单地触发更改事件。 –

回答

0

编辑1:

什么是tablelist?如何将表格中的值设置为文本框?如果您自己的js代码正在这样做,那么您可以在设置该值后简单地触发更改事件。

// code from below to bind to the change event. 
// ... 
// some code to set textbox value from tablelist. 
// ... 
$('#deviceType1').change(); // this will trigger the change event. 
          // ensure you have already bound to the change event. 

您需要订阅时在文本框中的文本已经改变,将通知您的事件。理想情况下,该事件应该是change事件。

$('#deviceType1').change(function() { 
    // value changed. write code to update the combox box. 
}); 

然而,变化事件似乎火,只有当文本框失去焦点:您可以按如下编写代码。如果这个限制没有问题,那么你的问题就解决了。但是,如果要在发生变化时捕获变化,则需要订阅各种事件以处理键盘输入和鼠标输入,以及用户可能会将某些内容粘贴到文本框中的情况。

这是@mdmullinax的一个答案,它建议您可以绑定的所有可能的事件,以处理您需要支持的情况。

https://stackoverflow.com/a/6140270/30007。请参阅更新提琴的评论:http://jsfiddle.net/pxfunc/zJ7Lf/1/

+0

:我希望任何值从我的文本框中的tablelist应显示在我的下拉框中作为默认值.... – Tina

+0

没有.....实际上,我已经创建了一个文本框和网格内的一个下拉列表(初始值为下拉框为空)...我有一个详细信息按钮在网格时smone击中的细节它显示现在我想要当smone击中细节其显示下拉值也现在的所有值,我有代码这个代码来获得价值现在我想用值替换代码...请帮助document.getElementById(“editdevicetype”)。value = dtype – Tina