JavaScript中没有反映文本框更改

时间:2012-12-19 05:13:21

标签: c# javascript asp.net

我有以下JavaScript函数。我有两个文本框,两个隐藏字段和两个标签。和一个按钮。点击按钮,我正在调用此功能。

在文本框中键入值时,它显示autoCompleteList。在从中选择一个值时,它从DB中获取值并填充相应的标签。此外,它同时将相应的选定值存储在hiddenfield中。

每当更改文本框中的值而不从autoPopulated列表中选择值时,它必须显示警报。

该功能工作正常,如果我填写单个文本框,但当我同时填充两者时,它会转到A点,而不是显示B点的警告

function ConfirmBox()
 {
    var txtBoxValue = document.getElementById("<%= txtFromPartNumber.ClientID %>").value;
    var txtBoxValue1 = document.getElementById("<%= txtToPartNumber.ClientID %>").value;
    var release = document.getElementById("<%= lblFromPartNumber.ClientID %>").innerText;
    var release1 = document.getElementById("<%= lblToPartNumber.ClientID %>").innerText;
    var hdnFromValueID = "<%= hdnFromReleaseNumber.ClientID %>";
    var hdnToValueID = "<%= hdnToReleaseNumber.ClientID %>";
     if ((txtBoxValue && txtBoxValue.trim() != "" && release))
     {
         if (document.getElementById(hdnFromValueID).value.trim() == txtBoxValue.trim()) 
         {
             if ((txtBoxValue1 && txtBoxValue1.trim() != "" && release1))  
             {
                 if (document.getElementById(hdnToValueID).value.trim() == txtBoxValue1.trim()) 
                 {
                    return true; //Point A
                 }
                 else
                 {// Point B
                     //alert("To Part no. has been changed. Please enter it again.");
                     var msg = document.getElementById("alertMessage");
                     msg.innerHTML = "To Part no. has been changed. Please enter it again.";
                     var myExtender = $find("ctl00_ContentPlaceHolder1_ModalPopupExtenderAlert");
                     myExtender.show();
                     document.getElementById("<%= txtToPartNumber.ClientID %>").focus();
                     return false;
                 }
             }
             else 
             {
                 //window.alert("Please choose a Valid To Part number");
                 var msg = document.getElementById("alertMessage");
                 msg.innerHTML = "Please choose a Valid To Part number.";
                 var myExtender = $find("ctl00_ContentPlaceHolder1_ModalPopupExtenderAlert");
                 myExtender.show();
                return false;
             }
         }
         else 
         {
             //alert("From Part no. has been changed.Please enter it again.");
             var msg = document.getElementById("alertMessage");
             msg.innerHTML = "From Part no. has been changed.Please enter it again.";
             var myExtender = $find("ctl00_ContentPlaceHolder1_ModalPopupExtenderAlert");
             myExtender.show();
             document.getElementById("<%= txtFromPartNumber.ClientID %>").focus();
             return false;
         }
     }
     else 
     {
         //window.alert("Please choose a Valid From Part number");
         var msg = document.getElementById("alertMessage");
         msg.innerHTML = "Please choose a Valid From Part Number.";
         var myExtender = $find("ctl00_ContentPlaceHolder1_ModalPopupExtenderAlert");
         myExtender.show();
         return false;
     }
 }

0 个答案:

没有答案