NinjaBoy
NinjaBoy

Reputation: 3745

jquery - How to get the value from a textbox?

Hi everyone Im trying to get the value of textbox whenever the user clicks on the textbox using jquery but when I used alert() to see the values here's what I got:

function (value) {
var hooks, ret, elem = this[0];
if (!arguments.length) {
    if (elem) {
        hooks = jQuery.valHooks[elem.nodeName.toLowerCase()] ||
            jQuery.valHooks[elem.type];
        if (hooks &&
            "get" in hooks &&
            (ret = hooks.get(elem, "value")) !== undefined) {
            return ret;
        }
        ret = elem.value;
        return typeof ret === "string" ? ret.replace(rreturn, "") : ret == null ? "" : ret;
    }
    return undefined;
}
var isFunction = jQuery.isFunction(value);
return this.each(function (i) {var self = jQuery(this), val;if (this.nodeType !== 1) {return;}if (isFunction) {val = value.call(this, i, self.val());} else {val = value;}if (val == null) {val = "";} else if (typeof val === "number") {val += "";} else if (jQuery.isArray(val)) {val = jQuery.map(val, function (value) {return value == null ? "" : value + "";});}hooks = jQuery.valHooks[this.nodeName.toLowerCase()] || jQuery.valHooks[this.type];if (!hooks || !("set" in hooks) || hooks.set(this, val, "value") === undefined) {this.value = val;}});}

Here is my code: http://jsfiddle.net/QYHXu/1/

Please help. Thanks a lot in advance.

Upvotes: 2

Views: 2523

Answers (4)

Ali Foroughi
Ali Foroughi

Reputation: 4599

you have forgotten the parenthesis dude for val function :)

Upvotes: 3

coder
coder

Reputation: 13250

Try this

$(function(){
    $('input#txtName').click(function () {
        alert(document.getElementById('txtName').value);
    });
});

Upvotes: 1

Awais Qarni
Awais Qarni

Reputation: 18006

Change your val function

From

$(this).val);

To

$(this).val());

Upvotes: 3

Jim H.
Jim H.

Reputation: 5579

$(this).val

...is a function.

$(this).val()

...is the return value from that function. Use $(this).val().

Upvotes: 10

Related Questions