Sarawut Positwinyu
Sarawut Positwinyu

Reputation: 5042

How to get value from a textbox that being autocompleted in jquery or javascript

There is a textbox that being autocompleted on load. Suppose that it is a email textboxl

    $(document).ready(function () {

        var email = $("#txtEmail").text();

    });

I try to get the value by this code, but it always return null. how to get that email value being autocomplted ?

Upvotes: 0

Views: 310

Answers (5)

Kamal
Kamal

Reputation: 2180

Check Demo .. i think this is what you actually want

UPDATES

check one more demo

Upvotes: 1

Kaidul
Kaidul

Reputation: 15855

For retrieving value from a input field like textarea, text you have to use val() and for getting value form a regular html tag like label, span, h1, h2 etc you have to use text()

$('#input_textarea').val(); //right way
$('#input_textarea').text(); // wrong way.returns null

$('#regular_html_tag').text(); // right way
$('#regular_html_tag').val(); // wrong way.It returtns NaN (not a number)

Upvotes: 1

Anupam
Anupam

Reputation: 210

you can use if only one input type this link other wise use $("id of emial field").val(); if you have only one input type on your page you can use:

Upvotes: 1

ahren
ahren

Reputation: 16961

var email = $("#txtEmail").val()

Upvotes: 5

Sang Suantak
Sang Suantak

Reputation: 5265

You use .val() for that:

var email = $("#txtEmail").val();

Upvotes: 3

Related Questions