空错误即将来临document.getElementByid(“dthchannel”+ [i]为null)

时间:2011-03-22 10:09:47

标签: javascript

function validate()
    {
    var flag=0;
    var spchar=/^[a-zA-Z0-9 ]*$/;
    var num=/^[0-9]*$/;

    var custid = document.getElementById('CUSTOMERID').value;
    var phoNo = document.getElementById('PHONENO').value;
    var emailId = document.getElementById('EMAILID').value;
    var channel = document.getElementById('CHANNELDTL').value;


    if(channel=="")
    {
        alert("You have not selected any channel");
        flag=1;
        return false;
    }

     if(custid=="" || custid==null )
        {
           alert("Please enter Customer ID");
           document.getElementById('CUSTOMERID').focus();
           flag=1;
           return false;
        }
     if (custid.search(num)==-1)
        {   
            alert("Customer should be Numeric");
            document.getElementById('CUSTOMERID').focus();
            flag=1;
            return false;
        }   
        if(phoNo=="" || phoNo==null )
        {
           alert("Please enter Phone");
           document.getElementById('PHONENO').focus();
           flag=1;
           return false;
        }
     if (phoNo.search(num)==-1)
        {   
            alert("Phone should be Numeric");
            document.getElementById('PHONENO').focus();
            flag=1;
            return false;
        }
        if(emailId=="" || emailId==null )
        {
           alert("Please enter Email");
           document.getElementById('EMAILID').focus();
           flag=1;
           return false;
        }
     if (emailId)
      {
            if(isValidEmail(document.getElementById('EMAILID').value) == false)
            {
                    alert("Please enter valid Email");
                    document.getElementById('EMAILID').focus();
                    flag=1;
                    return false;
           }
       }



    if(flag==0)
    {
        var emailid=Base64.tripleEncoding(document.getElementById('EMAILID').value);
        document.getElementById('E_EMAIL').value=emailid;
        document.getElementById('EMAILID').value="";

            var mobileno=Base64.tripleEncoding(document.getElementById('PHONENO').value);
        document.getElementById('E_PHONE').value=mobileno;
        document.getElementById('PHONENO').value="";

        var customerid=Base64.tripleEncoding(document.getElementById('CUSTOMERID').value);
        document.getElementById('E_CUSTID').value=customerid;
        document.getElementById('CUSTOMERID').value="";

        document.topupsform.action="../dth/leads/channelMail/channelMailUtil.jsp";
        document.topupsform.submit();
        alert("Thank you for choosing A-La-Carte services.\nWe will process it within 24 hours.\nYou will soon receive confirmation on your mail id.");
    }
}

function isValidEmail(Email) 
        {
            var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
            var address = trim(Email);
            if(reg.test(address) == false) 
            {  
                return false; 
            }
            else
                return true; 
        }

function trim(str) 
{
            str = this != window? this : str;
            return str.replace(/^\s+/g, '').replace(/\s+$/g, '');
}


function sendMail()
{
    caltotal();
    validate();

}


//----------------------------------
var counter = 0;

function resetcheckboxValue(){

    //var totalinputs = document.topupsform.getElementsByTagName("input");
    var totalinputs =document.getElementsByName("dthchannel");
    var totallenght = totalinputs.length;
    counter = 0;
    for(var i = 0; i < totallenght; i++) {
    // reset all checkboxes 

    document.getElementsByName("dthchannel")[i].checked = false;
    document.getElementById("totalamount").value = "0";
    document.getElementById("youpay").value = "0";

    }

}

function caltotal()
{
var plansObj =  document.getElementsByName("dthchannel");
var plansLength = plansObj.length;
counter = 0;
var finalNameValue = "";
for(var i = 1; i <= plansObj.length+1; i++) {
    if ( document.getElementById(("dthchannel")+ [i]).checked)
      {
           var gvalue = parseInt(document.getElementById(("dthchannel")+[i]).value);
           var gNameValue= document.getElementById("CHANNELNAME"+i).value+"~"+gvalue+"#";

          finalNameValue+= gNameValue;
          counter+= gvalue;
          }
    showresult();
    }
    var finallist = finalNameValue.substring(0,finalNameValue.length-1);
    //alert("finallist" +finallist);
document.getElementById("CHANNELDTL").value= finallist;

}


function showresult(){

    if(counter <= 150 && counter > 0){
     document.getElementById("youpay").value = "150";
     document.getElementById("totalamount").value = counter;         
    }
    else
    {
         document.getElementById("youpay").value = counter;
         document.getElementById("totalamount").value = counter;
    }
     }


window.onload = resetcheckboxValue;

1 个答案:

答案 0 :(得分:1)

你需要修改看起来像这样的行:

var gvalue = parseInt(document.getElementById("dthchannel" + i).value);

你不想做document.getElementById(("dthchannel") + [i]),因为我以前从未见过它,我认为它不起作用。