![](/img/trans.png)
[英]Validation for my ASP textboxes is not working using javascript and ASP.NET
[英]ASP.net help regarding Javascript and input from textboxes
這是我正在處理的網頁的基本流程:
除了第一項(從服務器檢索日期)以外,大多數工作都是由Javascript完成的。
所以這是我正在使用的Javascript:
function setHours(setting)
{
var tempVal = document.getElementById('<%=Text6.ClientID%>');
var nHours;
var textHours = new DateTime(tempVal);
alert(tempVal);
textHours = getHours
if (setting==true) {
nHours = 4;
alert("4");
}
else {
nHours = 4.5
alert("4.5");
}
textHours.setHours(textHours.getHours() + nHours);
document.getElementById("text8").value = textHours;
}
當用戶單擊兩個單選按鈕之一時(一個傳遞為true,另一個傳遞為false),將調用此函數。 請注意,我的“警報”遍布各處,因為最初,我無法啟動整個函數。 因此,我注釋掉了除了“ if語句”和“警報”之外的所有內容,並且瞧瞧它工作正常。
我假設問題出在var中的某個地方,也許是“ tempVal”如何檢索text6中的值。
這是文本框的代碼。
<form id='frmRequestApplicationForm' name='frmRequestApplicationForm' action='#' method='post'>
<input class="textboxdefault" type="text" name="Starttime" id="Text6" value="<%=(requestApplicationForm.StartimeError.ToString().Equals("")?requestApplicationForm.StarttimeDate.ToShortDateString().Equals("1/1/0001")?"":requestApplicationForm.StarttimeDate.ToShortTimeString(): requestApplicationForm.Starttime)%>"/>
</form>
構建程序使我得到一個“ Text6不存在”的信息。 我不確定代碼在哪里拒絕工作。
用簡單的“ Text6”替換“ <%= Text6.ClientID%>”會使整個Javascript函數失敗。
我可以幫忙嗎?
沒關系。
我將“ document.getElementById('<%=Text6.ClientID%>');
”替換為
document.frmRequestApplicationForm.Text6.value;
似乎現在工作正常。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.