javascript - Dropdown box - onchange and onselect - Stack Overflow

I want help, i am very new to html..On selecting option from dropdown menu, I want html to put the valu

I want help, i am very new to html..

On selecting option from dropdown menu, I want html to put the values in word.. e.g. When I select "1" from drop down, it must show "one" When I select "2' from drop down, it must show "two"

How to do that??

<HTML>
<Table border=10>

<TR>
<TD>Select Number</TD>
<TD><Select>
<option>1</option>
<option>2</option>
<option>3</option>
</Select></TD>
</TR>

<tr>
<td>In Words</td>
<td><input type="text" readonly></td>
</tr>

</Table>
</HTML>

Please make a script and show me...

I want help, i am very new to html..

On selecting option from dropdown menu, I want html to put the values in word.. e.g. When I select "1" from drop down, it must show "one" When I select "2' from drop down, it must show "two"

How to do that??

<HTML>
<Table border=10>

<TR>
<TD>Select Number</TD>
<TD><Select>
<option>1</option>
<option>2</option>
<option>3</option>
</Select></TD>
</TR>

<tr>
<td>In Words</td>
<td><input type="text" readonly></td>
</tr>

</Table>
</HTML>

Please make a script and show me...

Share Improve this question edited Mar 6, 2015 at 14:30 Ataullah asked Mar 4, 2015 at 7:46 AtaullahAtaullah 351 silver badge4 bronze badges 2
  • Please be more clear what your question is. – EternalHour Commented Mar 4, 2015 at 9:45
  • I have given example.. do refer to it.. – Ataullah Commented Mar 6, 2015 at 14:31
Add a ment  | 

2 Answers 2

Reset to default 2

A non-jQuery solution:

Firstly, give your select- and input-tags id's, and your options values (value=""). Then add a onchange=""-listener in the select-tag and make a function that carries out what you want to do (i.e. checking the selected value and displaying it in your input field), like so:

function showValue() {
    var x = document.getElementById("mySelect").value;
    document.getElementById("mySelection").value = "You selected: " + x;
}
<Table border=10>
<tr>
    <td>Select Number</td>
    <td><Select onchange="showValue()" id="mySelect">
    <option value="1">1</option>
    <option value="2">2</option>
    <option value="3">3</option>
    </Select></td>
</tr>

<tr>
    <td>In Words</td>
    <td><input type="text" id="mySelection"></td>
</tr>

</Table>

If I understand what you want, you'll need some javascript to find what you selected, and take that 'string' and shove it in an element for the user to see.

Here is a working example. Try making one these next time you ask a question. Wele to Stack Overflow.

http://jsfiddle/sheriffderek/6vp5Lskn/

HTML

<select name='my_select' id='my_select'>

    <option value='1'>Option 1</option>
    <option value='2'>Option 2</option>
    <option value='3'>Option 3</option>
    <option value='4'>Option 4</option>
    <option value='5'>Option 5</option>

</select>

<div id="oute">
    You have selected: <span></span>
</div>


javascript (jQuery)

var selectedOption; // define this variable

// when the select is changed...
$('#my_select').on('change', function() {
    // get the option that was selected
    selectedOption = $( "#my_select option:selected" ).text();
    // put the option in the place you want it
    $('#oute span').html(selectedOption);
});

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745359788a4624305.html

相关推荐

  • javascript - Dropdown box - onchange and onselect - Stack Overflow

    I want help, i am very new to html..On selecting option from dropdown menu, I want html to put the valu

    4小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信