O'Reilly logo

jQuery and JavaScript Phrasebook by Brad Dayley

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Getting and Setting Text Input Values

var inText = $("#inBox").val(); if (inText != "default"){   $("#outBox").val(inText); }

The most common type of form elements are textual inputs. These elements include the <textarea> element as well as <input> elements with the following type attribute values: color, date, datetime, datetime-local, email, month, number, password, range, search, tel, text, time, url, and week.

Although the browser uses these values a bit differently, all are rendered in the same basic text box and are accessed in the same basic way. Each of them has a value attribute that is displayed in the text box as the image is rendered.

In jQuery, you can access the value text inputs using the .val() ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required