Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jquery/Javascript Setting the attribute value of a textfield

I have a

<input type='text' id='text' value='' /> 

How do I programmatically set the value attrribute using JQuery/Javascript

like image 680
AJM Avatar asked Aug 03 '09 13:08

AJM


People also ask

How do I set the value of a element in jQuery?

jQuery val() Method The val() method returns or sets the value attribute of the selected elements. When used to return value: This method returns the value of the value attribute of the FIRST matched element.

What does VAL () do in jQuery?

val() method is primarily used to get the values of form elements such as input , select and textarea . When called on an empty collection, it returns undefined .


1 Answers

The simple easy way is:

$("#text").val ("foo"); 
like image 73
Bojan Rajkovic Avatar answered Sep 27 '22 19:09

Bojan Rajkovic