i have a combo box in html and text box where i input some text i want when i select any number from combo box then size of text which is in text box change according to that how to do this please help me
Thanks in advance
i have a combo box in html and text box where i input some text i want when i select any number from combo box then size of text which is in text box change according to that how to do this please help me
Thanks in advance
You can use jQuery To Simple down the code
HTML CODE:
<input type="text" value="Sample Text" id="txtBox" name="name">
<br>
<select id="fontSizeDD">
<option value='12'>12</option>
<option value='14'>14</option>
<option value='16'>16</option>
<option value='18'>18</option>
<option value='20'>20</option>
<option value='22'>22</option>
<option value='24'>24</option>
<option value='26'>26</option>
</select>
jQuery CODE :
$(function(){
$("#fontSizeDD").change(function(){
$("#txtBox").css("font-size",$(this).val() + "px");
})
});
Pure JavaScript Solution
var fontSizeDD = document.getElementById('fontSizeDD');
fontSizeDD.onchange = function () {
var txtBox = document.getElementById("txtBox")
txtBox.style.fontSize = this.value +"px";
};
If you use jQuery you can write an on change handler for the combo box and use
$("#textBox").css("font-size",$(this).val() + "px");
Like
$("#comboBox").change(function() {
$("#textBox").css("font-size",$(this).val() + "px");
});
This is a fully working example: (available on jsbin link)
<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-git2.js"></script>
<meta charset="utf-8">
<title>Text Area Size</title>
</head>
<body>
<select onchange="$('#txt').css('font-size', event.target.value + 'px')">
<option value="10">10</option>
<option value="20">20</option>
<option value="30">30</option>
</select>
<textarea id="txt">Test Test</textarea>
</body>
</html>