Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make text input box resizable (like textarea) by dragging its right-bottom corner using jQuery?

I would like to have (preferrably in jQuery) regular text input box which can be clicked and dragged by its right-bottom corner (e.g. like textareas have in Chrome) and resized by user ?

Can't find any jQuery plugin already implementing this. Can anybody give me hint if something like this exists or how could it be easily implemented ?

Thank you in advance.

EDIT: I want to be resizable similarly like textarea is in Chrome...

like image 290
Frodik Avatar asked Dec 20 '11 07:12

Frodik


People also ask

How do you make a textbox resizable?

Resize a text box Select the text box. Select one of the handles and drag until the text box is the size you want.

How to use resizable in jQuery?

Enable any DOM element to be resizable. With the cursor grab the right or bottom border and drag to the desired width or height.

How do I reduce the width of a text box?

On the Layout tab in the Textbox Width field you can adjust the textbox width. The default width for Textboxes is 20 characters. By specifying a value larger or smaller than 20 you can increase or decrease the width of the Textbox.

How do you enter a text box in HTML?

The <input type="text"> defines a single-line text field. The default width of the text field is 20 characters. Tip: Always add the <label> tag for best accessibility practices!


3 Answers

You don't need jQuery to handle this. What you need is css.

#yourTextInput{
resize:both;
}

This will allow your text input to have the resize option on the right

like image 66
XepterX Avatar answered Nov 07 '22 09:11

XepterX


Anno 2016 it is a bit more complicated. You need to wrap the <input> in an "inline-block" that you made resizable:

.resizable-input {
    /* make resizable */
    overflow-x: hidden;
    resize: horizontal;
    display: inline-block;

    /* no extra spaces */
    padding: 0;
    margin: 0;
    white-space: nowrap;
  
    /* default widths */
    width: 10em;
    min-width: 2em;
    max-width: 30em;
}

/* let <input> assume the size of the wrapper */
.resizable-input > input {
    width: 100%;
    box-sizing: border-box;
    margin: 0;
}

/* add a visible handle */
.resizable-input > span {
    display: inline-block;
    vertical-align: bottom;
    margin-left: -16px;
    width: 16px;
    height: 16px;
    background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAQAAAC1+jfqAAAAJUlEQVR4AcXJRwEAIBAAIPuXxgiOW3xZYzi1Q3Nqh+bUDk1yD9sQaUG/4ehuEAAAAABJRU5ErkJggg==");
    cursor: ew-resize;
}
<span class="resizable-input"><input type="text" /><span></span></span>
like image 40
kay Avatar answered Nov 07 '22 07:11

kay


Have you looked at the jQuery UI resizable widget?

Here is the source code for just the resizable example.

like image 1
PatrikAkerstrand Avatar answered Nov 07 '22 09:11

PatrikAkerstrand