ASP.net关于Javascript和文本框输入的帮助

ASP.net help regarding Javascript and input from textboxes

本文关键字:输入 帮助 文本 net 关于 Javascript ASP      更新时间:2023-09-26

以下是我正在处理的网页的基本流程:

  • 用户点击一个按钮,日期/时间选择器弹出(工作)
  • 一个时间字符串填充一个文本框,比如说,凌晨4:00(有效)
  • 然后,用户必须从两个单选按钮中选择一个,该按钮应读取文本框中的时间,单选按钮1增加4小时,单选按钮2增加4.5小时(不起作用)
  • 然后,总小时数显示在另一个文本框中(尚未显示)

除了第一项(从服务器检索日期)之外,大部分工作都是由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),就会调用此函数。请注意,我的"alert"分散在各处,因为最初,我无法启动整个功能。所以我评论了除了"if语句"answers"alert"之外的所有内容,你瞧,它运行得很好。

我假设问题出在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;

现在似乎工作得很好。