Hazel Mahmud

Hazel Mahmud

  • 1.4k
  • 315
  • 70.7k

div length according to textbox size

Jun 8 2015 10:49 PM
i manage to do expand textbox according to text character but i can't find any reference or site that shows how to expand div according to textbox size.. how do i do that.. my sample code are as below..
 
 
<script type="text/javascript" >
$(document).ready(function () {

var counter = 2;

$("#btnAdd").click(function () {

if (counter > 4) {

return false;
}

var newTextBoxDiv = $(document.createElement('div'))
.attr("id", 'TextBoxDiv' + counter);


newTextBoxDiv.after().html('<div class="divWidth" style="background-color:aquamarine; height:50px; width:100px" ><input type="text" name="textbox' + counter + '" size="1' + '"class="inputWithImge"' +
'" onkeyup="Expand(this);"' + '" id="textbox' + counter + '" value=""/>&nbsp;' +

newTextBoxDiv.appendTo("#LinkTab");

$('#textbox' + counter).focus();
counter++;
});

});

function Expand(obj) {
if (!obj.savesize)
obj.savesize = obj.size;
obj.size = Math.max(obj.savesize, obj.value.length);
}


</script> 

Answers (2)