我正在尝试获取控件的值,如下所示:
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; }
}
并且CONFIRM框根本没有开火!我没有弹出任何东西。
我尝试使用firefox进行调试,并且一旦进入此行:
confirmationMessage = "Please review the data before submitting:" + "\r"
+ "Sample Received Date: " + document.getElementById(re.......
它逃脱了函数
我在做错了什么?我怎样才能获得所有控件的值?答案 0 :(得分:2)
您需要为value
使用小写“v”并引用您的元素ID。例如:
document.getElementById("received_dateTextbox").value
由于您似乎已经在使用jQuery,因此您可以使代码更简洁。所以document.getElementById("received_dateTextbox").value
变为:
$("#received_dateTextbox").val()
答案 1 :(得分:2)
没有名为spec_idTextBox
的变量
您可能想要传递一个字符串文字。
修复后,您需要使用小写的.value
答案 2 :(得分:1)
如果您使用的是动态客户端ID,则必须内联呈现ID或将其传递给您的函数:
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;