Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Jan 2012
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Can't get concatenation to work?

    I'm pretty new to Javascript programming. I have this function I created that is basically pretty simple. It does edit checks, however, at the end of my script, I display an error message using an alert statement and at the end of the first sentence, the word "undefined" shows up before the line break. The only thing I can think of that is causing it is the "+" sign. Here is my code below:

    Code:
            function CheckEdits() {
                var msg;
    
                ok = true;
    
                if (document.getElementById("txtName").value == '') {
                    msg = msg + '\nName';
                    ok = false;
                }
    
                if (document.getElementById("txtOrganization").value == '') {
                    msg = msg + '\nOrganization';
                    ok = false;
                }
    
                if (document.getElementById("txtSubject").value == '') {
                    msg = msg + '\nSubject';
                    ok = false;
                }
    
                if (document.getElementById("txtNote").value == '') {
                    msg = msg + '\nNote';
                    ok = false;
                }
    
                if (msg != '') {
                    var msg2;
                    msg2 = "Please provide the following:\n" + msg;
                    alert(msg2);
                }            
            }
    What am I doing wrong?

    Thanks!
    Attached Thumbnails Attached Thumbnails Can't get concatenation to work?-errormsg.jpg  

  • #2
    Senior Coder jmrker's Avatar
    Join Date
    Aug 2006
    Location
    FL
    Posts
    3,146
    Thanks
    39
    Thanked 505 Times in 499 Posts
    Check the spelling and case of your id of 'txtName' element in the HTML portion not shown.


  •  

    Posting Permissions

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