0

i am getting this error 'Uncaught TypeError: undefined is not a function' for systemUsername. I have been at this for over 2 hours now, i dont understand how this isn't defined?

function systemUsername()
{
/*consists of the first
alphabetic characters found in the Family name, street address, Given name; the numerical day of the
month; and the numerical seconds field of the time of submission. E.g.: A user registers with name
Bernardo O’Higgins, address 213 Liberator St, at 12:31:16 on 25 April 2014. His system username is
OLB2516*/

var systemUsername = document.createElement("systemUsername");
var lastname = document.forms["userinfo"]["famName"].value;
var Address = document.forms["userinfo"]["address"].value;
//var withNoDigits = address.replace(/[0-9]/g, '');
var firstname = document.forms["userinfo"]["firstName"].value;
var dateStamp = new Date();
var dayNum = dateStamp.getDate();
var Seconds = dateStamp.getSeconds();

if (dayNum<10)
{
    var x = '0';
    dayNum = x + dayNum;
}
    alert(dayNum);

if (Seconds<10)
{
    var x = '0';
    Seconds = x + Seconds;
}
    alert(Seconds);

var tempSU = lastname.charAt(0)+Address.charAt(0)+firstname.charAt(0)+dayNum.charAt(0)+dayNum.charAt(1)+Seconds.charAt(0)+Seconds.charAt(1);
systemUsername.setAttribute("type", "hidden");
systemUsername.setAttribute("name", "systemName");
systemUsername.setAttribute("value", "tempSU");
document.getElementById("userinfo").appendChild(systemUsername);
alert("tempSU: ".tempSU);

}

Alex94
  • 27
  • 5
  • Can you please elaborate your question. There' no calls to `systemUsername` in the provided snippet. What has the question to do with `document.createElement`? – Teemu May 30 '14 at 10:03
  • _Again_ with a new account? [This](http://stackoverflow.com/q/23939739/1169519) and [this](http://stackoverflow.com/q/23932125/1169519) are your questions? Asked using three different accounts? – Teemu May 30 '14 at 10:20
  • Sorry i am new here, but the error is highlighting on the setAttribute function of the systemUsername element that i created. – Alex94 May 30 '14 at 10:20
  • those aren't my questions? – Alex94 May 30 '14 at 10:21
  • Honestly? The concept is the same and "`Bernardo O’Higgins`" connects you to these questions... – Teemu May 30 '14 at 10:25
  • Haha honestly just a coincidence man. This is a question from a major assessment due tomorrow night, the two other questions must be other people struggling with it. – Alex94 May 30 '14 at 10:28

1 Answers1

0

Try this, use + for concatenation instead of .

alert("tempSU: " + tempSU);

instead of

 alert("tempSU: ".tempSU);

Demo: http://jsfiddle.net/5yXAL/

Krish R
  • 22,583
  • 7
  • 50
  • 59
  • This won't cause error, it just will alert `undefined`. A place for a fix though. – Teemu May 30 '14 at 10:08
  • I dont understand, after changing the '.' to a '+' it is still throwing me the same undefined? @Teemu – Alex94 May 30 '14 at 10:16