Reputation: 3745
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
Reputation: 13250
Try this
$(function(){
$('input#txtName').click(function () {
alert(document.getElementById('txtName').value);
});
});
Upvotes: 1
Reputation: 18006
Change your val
function
From
$(this).val);
To
$(this).val());
Upvotes: 3
Reputation: 5579
$(this).val
...is a function.
$(this).val()
...is the return value from that function. Use $(this).val()
.
Upvotes: 10