在特定表单元素发生变化时动态添加社交引擎表单元素

发布于 2025-01-07 17:01:02 字数 110 浏览 0 评论 0原文

我是 SE 4.20 的新手。我在更改此表单元素时创建表单元素时遇到问题。

为了解释, 我有一个表格。我能够在更改此表单元素时返回一些选择选项值。但现在我想在更改此元素时添加一个表单元素。

I am new in SE 4.20. I am having a problem of creating a form element onchange of this form element.

For explanation,
I have a form. I am able to return some select option value on change of this form element. But now I want to add a form element on change of this element.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

饮湿 2025-01-14 17:01:02

如果用户更改选择框,您想添加一个表单元素(例如文本框)吗?也许是这样的:

$("#selectBoxId").change(function (){
    $("#formId").append("<input type='text' name='additionalFormElement' />");
});

You want to add a form element, like a text box, if the user changes the select box? Maybe something like:

$("#selectBoxId").change(function (){
    $("#formId").append("<input type='text' name='additionalFormElement' />");
});
弥繁 2025-01-14 17:01:02

这是 HTML:

<div class="form-elements">
<div id="typeName-wrapper" class="form-wrapper">
    <div id="typeName-label" class="form-label">
        <label for="typeName" class="required">Type</label>
    </div>
    <div id="typeName-element" class="form-element">
        <select name="typeName" id="typeName">
            <option value="Grant">Grant</option>
            <option value="Cooperative Agreements">Cooperative Agreements</option>
            <option value="Publication">Publication</option>
        </select>
    </div>
</div>
<div id="resourceName-wrapper" class="form-wrapper">
    <div id="resourceName-label" class="form-label">
        <label for="resourceName" class="required">Name</label>
    </div>
    <div id="resourceName-element" class="form-element">
        <select name="resourceName" id="resourceName">
            <option value="ABC">ABC</option>
            <option value="XYZ">XYZ</option>
        </select>
    </div>
</div>

这是 mootool js:

 $('typeName').addEvent('change', function(event) {
        var typeName = $('typeName').value;
        var base_path = "<?php echo $this->baseUrl();?>/";
        var url = 'http://xxxxxxx.com/test/resource/getresourcebytype';
        var request= new Request.JSON({
            url: url,
            method: 'GET',
            data: {"typeName":typeName},
            onSuccess: function( response )
            {
                console.log(response);
                //clear the select box
                var name = $('resourceName');
                while (name.firstChild) {
                    name.removeChild(name.firstChild);
                }
                //now add new option
                for (var i = 0; i < response.length; i++){
                    console.log(response[i]);
                    new Element('option', {'value': response[i].value, 'text':response[i].label}).inject(name);
                }

            }, onFailure: function(){

                console.log('failed');
            }
        });
        request.send();
    });

Here is the html:

<div class="form-elements">
<div id="typeName-wrapper" class="form-wrapper">
    <div id="typeName-label" class="form-label">
        <label for="typeName" class="required">Type</label>
    </div>
    <div id="typeName-element" class="form-element">
        <select name="typeName" id="typeName">
            <option value="Grant">Grant</option>
            <option value="Cooperative Agreements">Cooperative Agreements</option>
            <option value="Publication">Publication</option>
        </select>
    </div>
</div>
<div id="resourceName-wrapper" class="form-wrapper">
    <div id="resourceName-label" class="form-label">
        <label for="resourceName" class="required">Name</label>
    </div>
    <div id="resourceName-element" class="form-element">
        <select name="resourceName" id="resourceName">
            <option value="ABC">ABC</option>
            <option value="XYZ">XYZ</option>
        </select>
    </div>
</div>

Here are the mootool js:

 $('typeName').addEvent('change', function(event) {
        var typeName = $('typeName').value;
        var base_path = "<?php echo $this->baseUrl();?>/";
        var url = 'http://xxxxxxx.com/test/resource/getresourcebytype';
        var request= new Request.JSON({
            url: url,
            method: 'GET',
            data: {"typeName":typeName},
            onSuccess: function( response )
            {
                console.log(response);
                //clear the select box
                var name = $('resourceName');
                while (name.firstChild) {
                    name.removeChild(name.firstChild);
                }
                //now add new option
                for (var i = 0; i < response.length; i++){
                    console.log(response[i]);
                    new Element('option', {'value': response[i].value, 'text':response[i].label}).inject(name);
                }

            }, onFailure: function(){

                console.log('failed');
            }
        });
        request.send();
    });
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文