...

View Full Version : Can't get concatenation to work?



blakemckenna
01-01-2012, 06:41 PM
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:



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!

jmrker
01-01-2012, 06:50 PM
Check the spelling and case of your id of 'txtName' element in the HTML portion not shown.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum