开发者

Getting error while retrieveing value from name

I am beginner with jquery, I am getting error while getting input from name in jquery.. My code is... HTML

<input type="text" name="pcpfname" id="pcpfname" class="te开发者_开发技巧xt" />
<input type="submit" name="pcpsubmit" id="pcpsubmit" value="Submit" />

Jquery

$('#pcpsubmit').click(function(){
var pcpfname = $('input[name=pcpfname]');
alert (pcpfname);
});

My alert message is

[object Object]


use val() to get value

$('#pcpsubmit').click(function(){
var pcpfname = $('input[name="pcpfname"]');
alert (pcpfname.val());
});

and you should use " quotes to selecting name attr in latest versions


Try

var pcpfname = $('input[name="pcpfname"]').val();


You have to call val() on your input field.

$('#pcpsubmit').click(function(){
var pcpfname = $('input[name="pcpfname"]').val();
alert (pcpfname);
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜