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);
});
精彩评论