duanfu3634 2013-04-27 10:31
浏览 106
已采纳

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

How can I insert an additional input textbox after an onchange event in a selectbox with the YUI library?

It is required to use YUI and the form is created with the PEAR Quickforms lib.

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.

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. On the option change event I've tried to insert the raw html code at the right position with this:

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!

  • 写回答

1条回答 默认 最新

  • doujingxi3356 2013-04-29 11:51
    关注

    I solved it for me now with the...

    'style'=>'display:none'
    

    ...property in the quickform textinput element and use...

    document.getElementById('id of the input element').style.display = 'block';
    

    ... which is called on the onchange event.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 shape_predictor_68_face_landmarks.dat
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制