html - Building array in javascript -


i'm trying build array in javascript user input on html form. seems array building fine until gets .push, error

employeeid undefined

, though know it's being populated , can see when run debug mode.

html

  <div class="wel" align="left">      <form class="form-signin">          <p>             <input type="text" class="form-control" id="employeeid" name="employeeid" placeholder="employeeid" required="" autofocus="" />         </p>         <p>             <input type="text" class="form-control" id="fullname" name="fullname" placeholder="fullname" required="" autofocus="" />         </p>         <p>             <input type="text" class="form-control" id="username" name="username" placeholder="username" required="" autofocus="" />         </p>         <p>             <input type="email" class="form-control" id="email" name="email" placeholder="email" required="" autofocus="" />         </p>         <p>             <input type="password" class="form-control" id="password" name="password" placeholder="password" required="" autofocus="" />         </p>         <p>             <input type="password" class="form-control" id="password1" name="confirmpassword" placeholder="password" required="" autofocus="" />         </p>          <a id='subbutton' class="btn btn-primary btn-lg" style="vertical-align: bottom">submit</a>      </form> </div 

javascript

  $(document)     .ready(function() {          var arraydetails = new array();         var holdingarray = new array();          function newentry(employeeid, fullname, username, email, password) {              this.employeeid = employeeid;             this.fullname = fullname;             this.username = username;             this.email = email;             this.password = password;          }              $("#subbutton")             .click(function () {                  debugger;                  var success = true;                  var password = document.getelementbyid("password");                 var password1 = document.getelementbyid("password1");                  if (password.value !== password1.value)                 {                     alert("password not match");                 }                 else                 {                     var employeeidentered = document.getelementbyid("employeeid").value;                      if (employeeidentered === "") {                         success = false;                     }                      var fullnameentered = document.getelementbyid("fullname").value;                      if (fullnameentered === "") {                         success = false;                     }                      var usernameentered = document.getelementbyid("username").value;                      if (usernameentered === "") {                         success = false;                     }                      var emailentered = document.getelementbyid("email").value;                      if (emailentered === "") {                         success = false;                     }                      var passwordenterned = document.getelementbyid("password").value;                      if (passwordenterned === "") {                         success = false;                     }                      var entry = newentry(employeeidentered,                         fullnameentered,                         usernameentered,                         emailentered,                         passwordenterned);                      arraydetails.push(entry);                 };                  if (success)                 {                     sendtocontroller();                 } else                 {                     alert("");                 }              }); 

your newentry() function missing return statement. don't add attributes this, instead

function newentry(employeeid, fullname, username, email, password) {         var res = {};         res.employeeid = employeeid;         res.fullname = fullname;         res.username = username;         res.email = email;         res.password = password;         return res;     } 

Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -