1

I want to make an input field that has a min-width of 25px and a width of 10px per entered character. Therefore, each character entered after the second will increase the width of the input field. Lastly, the input field should become smaller when characters are deleted.

I just need an idea of how to solve the variable width based on input characters. Suggestions?

Thanks!

1 Answer 1

3

This is trivial.

<input type="text" style="width: 25px;"
               onKeyUp="this.style.width = Math.max(25,this.value.length*10)+'px';" />
Sign up to request clarification or add additional context in comments.

1 Comment

dammit. the fast answerers :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.