SE4.20は初めてです。このフォーム要素の変更時にフォーム要素を作成する際に問題が発生します。
説明のために、私はフォームを持っています。このフォーム要素を変更すると、いくつかの選択オプション値を返すことができます。しかし、ここで、この要素の変更時にフォーム要素を追加したいと思います。
SE4.20は初めてです。このフォーム要素の変更時にフォーム要素を作成する際に問題が発生します。
説明のために、私はフォームを持っています。このフォーム要素を変更すると、いくつかの選択オプション値を返すことができます。しかし、ここで、この要素の変更時にフォーム要素を追加したいと思います。
ユーザーが選択ボックスを変更した場合に、テキストボックスなどのフォーム要素を追加しますか?多分次のようなものです:
$("#selectBoxId").change(function (){
$("#formId").append("<input type='text' name='additionalFormElement' />");
});
これが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>
これがmootooljsです:
$('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();
});