简体   繁体   English

YUI JavaScript-选择onchange事件后如何添加输入文本框?

[英]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.

相关问题 如何在 Javascript 上添加 onChange 事件以仅重新加载选择选项 - How to add onChange event on Javascript to reload only the select option 如何在 CakePHP 中添加 onChange 事件以选择标记? - How do I add an onChange event to select tag in CakePHP? 如何在选择框中的Onchange事件中添加JQgrid元素中的函数 - How to add function in element of JQgrid like Onchange event in select box 输入文件的onchange事件后如何上传文件 - How to upload a file after the onchange event of file input javascript中的onChange事件未在选择框中触发 - onChange event in javascript is not triggering in select box 在OnChange事件后重置隐藏的选择值 - Reset hidden select value after OnChange event JavaScript OnChange选择值进入输入字段 - JavaScript OnChange select value into input field JavaScript:参数列表后未捕获到的SyntaxError:缺少)在添加带有onchange事件的行时 - JavaScript: Uncaught SyntaxError: missing ) after argument list while add rows with an onchange event 如何在select onChange事件上重定向到其他方式? - How to redirect to other way on a select onChange event? 从属YII输入框? 我的错误在哪里? 如何在dropDownList中添加Onchange事件? 不使用控制器 - Dependent YII Input Box? Where is my Mistake? How to add Onchange Event in dropDownList? without using controller
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM