Page 1 of 1

Javascript error

Posted: Thu Jan 04, 2007 12:57 pm
by shiznatix
I am trying to make a little required fields javascript popup but my Error Console keeps giving me an error saying 'undetermined string literal'. Heres my code:

Code: Select all

function CheckRequired()
    {
        var msg = '';

        if ('' == document.getElementById('Company').value)
            msg += "Company was empty\n";//this line at the start of the first quote is where it stops
        if ('' == document.getElementById('Contact').value)
            msg += "Contact was empty\n";
        if ('' == document.getElementById('Address').value)
            msg += "Address was empty\n";
        if ('' == document.getElementById('City').value)
            msg += "City was empty\n";
        if ('' == document.getElementById('Email').value)
            msg += "Email was empty\n";
        if ('' == document.getElementById('State').value)
            msg += "State was empty\n";
        if ('' == document.getElementById('Phone').value)
            msg += "Phone was empty\n";
        if ('' == document.getElementById('ZipCode').value)
            msg += "ZipCode was empty\n";

        if ('' != msg)
        {
            alert(msg);
            return false;
        }
        else
        {
            return true;
        }
    }
stranger yet is it gives that error on load, it does not wait till i call the function. am i missing something super stupid?

Posted: Thu Jan 04, 2007 1:09 pm
by Kieran Huggins
try:

Code: Select all

msg = msg + "Company was empty\n";
instead of:

Code: Select all

msg += "Company was empty\n";
does that work?

Posted: Thu Jan 04, 2007 1:17 pm
by shiznatix
gwarr i had to do \\n instead of \n because i was using heredocs or somtin. Thanks though