如何在NetSuite中动态更改下拉菜单

时间:2015-05-22 06:54:52

标签: javascript scripting netsuite

假设页面中有两个下拉菜单,我想根据第一个下拉菜单的选择更改第二个下拉菜单。

例如。

第一个下拉菜单包含记录类型列表。如果我选择customer记录类型,则第二个下拉菜单应自动更改为客户列表。与script deployments等相同。

不仅是下拉菜单,还有套件页面中的任何动态操作。

我尝试了什么

我已经创建了一个带有下拉菜单的suitelet。提交表单后,脚本将获取值并填充菜单。

var start = function(request, response) {
    if(request.getMethod() == 'GET') {
        var form1 = nlapiCreateForm('New Form 1');
        var select1 = form1.addField('custpage_select1', 'select', 'Select A record Type', '-123');
        form1.addSubmitButton('submit');
        response.writePage(form1);
    }
    else {
        var id = request.getParameter('custpage_select1');
        var form2 = nlapiCreateForm('New Form 2');
        var select2 = form2.addField('custpage_select2', 'select', 'Select A record Value', id);
        response.writePage(form2);
    }
}

我需要的是整个事物的单一形式。像,

var start = function(request, response)  {
    var form1 = nlapiCreateForm('New Form 1');
    var select1 = form1.addField('custpage_select1', 'select', 'Select A record Type', '-123');
    var select2 = form1.addField('custpage_select2', 'select', 'Select A record Type', XXXXX);//the source of the 1st select field
    form1.addSubmitButton('submit');
    response.writePage(form1);
}

1 个答案:

答案 0 :(得分:0)

Javascript代码



function configureDropDownLists(ddl1,ddl2) {
        var Customer = new Array('Customer1', 'Customer2', 'Customer3');
        var Script = new Array('Script1', 'Script2', 'Script3');
        var etc = new Array('etc1', 'etc2', 'etc3');
    
        switch (ddl1.value) {
            case 'Customer':
                ddl2.options.length = 0;
                for (i = 0; i < Customer.length; i++) {
                    createOption(ddl2, Customer[i], Customer[i]);
                }
                break;
            case 'Script':
                ddl2.options.length = 0; 
            for (i = 0; i < Script.length; i++) {
                createOption(ddl2, Script[i], Script[i]);
                }
                break;
            case 'etc':
                ddl2.options.length = 0;
                for (i = 0; i < etc.length; i++) {
                    createOption(ddl2, etc[i], etc[i]);
                }
                break;
                default:
                    ddl2.options.length = 0;
                break;
        }

    }

    function createOption(ddl, text, value) {
        var opt = document.createElement('option');
        opt.value = value;
        opt.text = text;
        ddl.options.add(opt);
    }
&#13;
<select id="ddl" onchange="configureDropDownLists(this,document.getElementById('ddl2'))">
<option value=""></option>
<option value="Customer">Customer</option>
<option value="Script">Script</option>
<option value="etc">etc</option>
</select>

<select id="ddl2">
</select>
&#13;
&#13;
&#13;

希望这有帮助