views:

36

answers:

2

Hello,

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 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

+1  A: 

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();
Sarfraz
+1  A: 

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!

Adam