dcsimg
www.webdeveloper.com
Results 1 to 2 of 2

Thread: java script error message: object required test.js line: x Code: 0 Char: 1

  1. #1
    Join Date
    Aug 2012
    Posts
    7

    java script error message: object required test.js line: x Code: 0 Char: 1

    java script error message: object required test.js line: x Code: 0 Char: 1

    Does anyone knows what's causing the error message.
    The function does work and i get the alerts but the error message prevents me from submitting it.

    Any help will be appreciated.




    function validateMeans()
    {
    var bus=document.getElementById('_1_1_32_1').value;
    var busp=document.getElementById('_1_1_47_1').value;

    var subway=document.getElementById('_1_1_31_1').value;
    var subwayp=document.getElementById('_1_1_46_1').value;

    var taxi=document.getElementById('_1_1_30_1').value;
    var taxip=document.getElementById('_1_1_48_1').value;

    var hotel=document.getElementById('_1_1_36_1').value;
    var hotelp=document.getElementById('_1_1_51_1').value;

    var Amtrak=document.getElementById('_1_1_33_1').value;
    var Amtrakp=document.getElementById('_1_1_49_1').value;

    var MTA=document.getElementById('_1_1_34_1').value;
    var MTAp=document.getElementById('_1_1_50_1').value;

    var Park=document.getElementById('_1_1_35_1').value;
    var Parkp=document.getElementById('_1_1_52_1').value;

    var alertMsg = "";

    //Taxi-------------------------------------------------
    if (((taxi!=null && taxi!="")&&(taxip==null || taxip=="")) || ((taxi==null || taxi=="")&&(taxip!=null && taxip!="")))
    {
    alertMsg += "If a taxi cost amount is entered, a payment mehtod is to be selected and vise versa. \n";
    }
    //Subway----------------------------------------------
    if (((subway!=null && subway!="")&&(subwayp==null || subwayp=="")) || ((subway==null || subway=="")&&(subwayp!=null && subwayp!="")) )
    {
    alertMsg += "If a subway cost amount is entered, a payment mehtod is to be selected and vise versa. \n";
    }
    //Bus---------------------------------------------------
    if (((bus!=null && bus!="")&&(busp==null || busp=="")) || ((bus==null || bus=="")&&(busp!=null && busp!="")))
    {
    alertMsg += " If a bus cost amount is entered, a payment mehtod is to be selected and vise versa. \n";
    }
    //Amtrak-------------------------------------------------
    if (((Amtrak!=null && Amtrak!="")&&(Amtrakp==null || Amtrakp=="")) || ((Amtrak==null || Amtrak=="")&&(Amtrakp!=null && Amtrak!="")))
    {
    alertMsg += " If an Amtrak cost amount is entered, a payment mehtod is to be selected and vise versa. \n";
    }
    //MTA Train----------------------------------------
    if (((MTA!=null && MTA!="")&&(MTAp==null || MTAp=="")) || ((MTA==null || MTA=="")&&(MTAp!=null && MTAp!="")))
    {
    alertMsg += " If a MTA Train cost amount is entered, a payment mehtod is to be selected and vise versa. \n";
    }
    // Parking------------------------------------
    if (((Park!=null && Park!="")&&(Parkp==null || Parkp=="")) || ((Park==null || Park=="")&&(Parkp!=null && Parkp!="")))
    {
    alertMsg += " If a Parking cost amount is entered, a payment mehtod is to be selected and vise versa. \n";
    }
    //--------------------------------------------------
    if (((hotel!=null && hotel!="")&&(hotelp==null || hotelp=="")) || ((hotel==null || hotel=="")&&(hotelp!=null && hotelp!="")))
    {
    alertMsg += "If a hotel cost amount is entered, a payment mehtod is to be selected and vise versa. \n";
    }

    if(alertMsg != "") {
    alertMsg = alertMsg.substr(0,alertMsg.length-1);
    alert(alertMsg);
    }
    }

  2. #2
    Join Date
    Nov 2006
    Location
    Oakland
    Posts
    500
    Fisrt of all, your javascript is too verbose. Did you know the empty string "", the undefined and null are all falsy values?
    That means the condition:
    if (((taxi!=null && taxi!="")&&(taxip==null || taxip=="")) || ((taxi==null || taxi=="")&&(taxip!=null && taxip!="")))

    can be just written:
    if ((taxi && !taxip) || (!taxi && taxip))

    May I suggest using the Developer Tools found in all major web browsers to really pinpoint the line number where the error is occurring.
    If you get the alert message then the problem may certainly not coming from the function.
    Beside when using a validation function, you should always return false when the validation failed and true otherwise.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles