Alex Gordon
Alex Gordon

Reputation: 60892

Getting values of all controls

i am trying to get the values of my controls like this:

 function ConfirmWithUser() 
        {
            var nodeText = '';
            $('.mytreeview input[@type=checkbox]:checked').each(function() {
                nodeText += $(this).next('a').text() + '\r';


            });
            var confirmationMessage;
            confirmationMessage = "Please review the data before submitting:" + "\r"
            + "Sample Received Date: " + document.getElementById(received_dateTextbox).Value + "\r"
            + "Site of Ocurrence: " + document.getElementById(site_of_occurrenceTextBox).Value + "\r"
            + "Occurrence Date: " + document.getElementById(occurrence_dateTextBox).Value + "\r"
            + "Report Date: " + document.getElementById(report_byTextBox).Value + "\r"
            + "Specimen ID: " + document.getElementById(spec_idTextBox).Value + "\r"
            + "Batch ID: " + document.getElementById(batch_idTextBox).Value + "\r\n"
            + "Report Initiated By: " + document.getElementById(report_byTextBox).Value + "\r\n"
            + "Problem Identified By: " + $("input[@name=RadioButtonList1]:checked").val() + "\r\n"
            + "Problem List: " + nodeText;

            HiddenFieldConfirmation.Value = confirmationMessage;

            if (confirm(document.getElementById('HiddenFieldConfirmation').value) == true)
            { return true; }
            else
            { return false; }
        }

and the CONFIRM box is not firing at all! i do not get any pop up.

i tried to debug using firefox, and as soon as it go to this line:

confirmationMessage = "Please review the data before submitting:" + "\r"
                + "Sample Received Date: " + document.getElementById(re.......

it escapes out of the function

what am i doing wrong? how can i get the values of all the controls?

Upvotes: 1

Views: 228

Answers (3)

rick schott
rick schott

Reputation: 21112

If you are using dynamic client ids, you have to render the ids inline or pass them to your function:

 confirmationMessage = "Please review the data before submitting:" + "\r"
            + "Sample Received Date: " + document.getElementById('<% = received_dateTextbox.ClientID %>').value + "\r"
            + "Site of Ocurrence: " + document.getElementById('<% = site_of_occurrenceTextBox.ClientID %>').value + "\r"
            + "Occurrence Date: " + document.getElementById('<% = occurrence_dateTextBox.ClientID %>').value + "\r"
            + "Report Date: " + document.getElementById('<% = report_byTextBox.ClientID %>').value + "\r"
            + "Specimen ID: " + document.getElementById('<% = spec_idTextBox.ClientID %>').value + "\r"
            + "Batch ID: " + document.getElementById('<% = batch_idTextBox.ClientID %>').value + "\r\n"
            + "Report Initiated By: " + document.getElementById('<% = report_byTextBox.ClientID %>').value + "\r\n"
            + "Problem Identified By: " + $("input[@name=RadioButtonList1]:checked").val() + "\r\n"
            + "Problem List: " + nodeText;

Upvotes: 1

SLaks
SLaks

Reputation: 888223

There is no variable named spec_idTextBox.
You probably want to pass a string literal.

Once you fix that, you need to use .value in lowercase

Upvotes: 2

gilly3
gilly3

Reputation: 91677

You need to use a lowercase "v" for value and quote your element ids. Eg:

document.getElementById("received_dateTextbox").value

Since it appears you are already using jQuery, you can make your code a little more concise. So document.getElementById("received_dateTextbox").value becomes:

$("#received_dateTextbox").val()

Upvotes: 2

Related Questions