[英]YUI JavaScript - How to add input textbox after select onchange event?
How can I insert an additional input textbox after an onchange event in a selectbox with the YUI library? 如何在带有YUI库的selectbox中的onchange事件之后插入其他输入文本框?
It is required to use YUI and the form is created with the PEAR Quickforms lib. 需要使用YUI,并且使用PEAR Quickforms库创建该表单。
What I have yet is this: 我还没有这个:
$form->addElement('select', 'names', "Choose Name", $options, array('style'=>'width:300px', 'onchange' => 'name_changed(this.value);'));
$js =
<<<EOS
<script type="text/javascript">
function name_changed(name) {
alert('name is changed');
}
</script>
EOS;
$form->addElement('static', 'jsembed', '', utf8_encode($js));
The alert pops up if I change the option in the selectbox, this works for testing. 如果我更改选择框中的选项,则会弹出警报,这可以进行测试。
Now I need to check the chosen option and if this equals 'NEW', there should appear a text input field to enter a new name under the select box. 现在,我需要检查所选的选项,如果这等于“ NEW”,则应该在选择框下方出现一个文本输入字段,以输入新名称。
My problem is, that I don't know to do it right that the entered name is also passed to the submitted quickform data. 我的问题是,我不知道正确的做法是将输入的名称也传递到提交的快速表格数据中。
So I've created the element normally with $form->addElement('input',...) and copied the html source of this. 因此,我通常使用$ form-> addElement('input',...)创建了元素,并复制了该元素的html源。 On the option change event I've tried to insert the raw html code at the right position with this:
在选项更改事件中,我尝试使用以下命令在正确的位置插入原始html代码:
var htmlContent = '<div id="fitem_id_dbname" class="fitem fitem_ftext"><div class="fitemtitle"><label for="id_dbname">Create new DB </label></div><div class="felement ftext" id="yui_275"><input size="60" name="dbname" type="text" value="" id="id_dbname"></div></div>';
document.getElementsByClassName('fcontainer clearfix').innerHTML = htmlContent;
But this doesn't work, there appears no input field in the browser. 但这不起作用,浏览器中没有输入字段。
Could anybody show me how to do it right? 有人可以教我如何做对吗? Lots of thanks!
非常感谢!
I solved it for me now with the... 我现在用...解决了
'style'=>'display:none'
...property in the quickform textinput element and use... 快速表单textinput元素中的属性并使用...
document.getElementById('id of the input element').style.display = 'block';
... which is called on the onchange event. ...在onchange事件上调用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.