开发者

Getting error while retrieveing value from name

开发者 https://www.devze.com 2023-04-03 08:05 出处:网络
I am beginner with jquery, I am getting error while getting input from name in jquery.. My code is... HTML

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

精彩评论

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