Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
331 views
in Technique[技术] by (71.8m points)

javascript - How to fill in a text field with drop down selection

I have a drop down with different strings, I want a text box to be filled in with the string of the drop down selected.

I am writing this in html

<td align="right">
        <select name="xyz" size="1">
          <option value=""></option>
          <?php foreach($comments as $comment): ?>
            <?if($comment->x!= 0):?>
              <option value="<?=$comment->x;?>"<?=($comment->x == $postData["xyz"] ? 'selected="selected"':"")?>>
                   <?=$comment->y;?>
              </option>
            <?endif;?>
          <?php endforeach; ?>
        </select>
        <textarea name="xz" cols="36" rows="3"><?=$postData["xz"];?></textarea>
</td>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Something like this jsfiddle demo?

HTML:

<textarea id="mytext"></textarea>

<select id="dropdown">
    <option value="">None</option>
    <option value="text1">text1</option>
    <option value="text2">text2</option>
    <option value="text3">text3</option>
    <option value="text4">text4</option>
</select>

JavaScript:

<script type="text/javascript">
    var mytextbox = document.getElementById('mytext');
    var mydropdown = document.getElementById('dropdown');

    mydropdown.onchange = function(){
          mytextbox.value = mytextbox.value  + this.value; //to appened
         //mytextbox.innerHTML = this.value;
    }
</script>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

Just Browsing Browsing

[3] html - How to create even cell spacing within a

1.4m articles

1.4m replys

5 comments

57.0k users

...