开发者

How do I reference a hidden input in a specifc form using jQuery?

I have a series of forms on a page that all have a recordId value as a hidden input. The form name/id is GPA-Entry-Form-1. I am trying to get the value of the 开发者_StackOverflow社区hidden field this way:

$('#deleteThisGPAEntry-1').click(function() {
    var recordId = $('GPA-Entry-Form-1 #recordId').val();
    alert('You clicked me. ID: ' + recordId);   
    return false;
});

Unfortunately, I am doing something wrong. When the button is clicked the alert comes up with the message and the value of the recordId is showing as undefined.

What am I doing wrong?

Thanks,

Josh


You forgot the pound sign! (Probably the most common jQuery mistake).

Assuming your form has GPA-Entry-Form-1 as the ID then use:

$('#GPA-Entry-Form-1 #recordId').val();

if it's the name then use:

$('form[name=GPA-Entry-Form-1] #recordId').val();

Either way you are using the descendent selector correctly. It should work.

Good Luck!


The form name/id is GPA-Entry-Form-1

You need to specify the form id by prefixing #:

var recordId = $('#GPA-Entry-Form-1 #recordId').val();
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜