This way you can do using the size attribute
<input type="text" id="name" value="Mudassar" size="8" />
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
$(function () {
$("#name").keyup(function () {
$(this).attr("size", this.value.length);
});
});
</script>
Demo