动态社交引擎表单元素添加特定表单元素的更改

时间:2012-02-21 05:18:09

标签: php socialengine

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

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

2 个答案:

答案 0 :(得分:0)

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

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

答案 1 :(得分:0)

这是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();
    });