SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Jun 2010
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Help with stringing variables

    I don't know why this keeps happening, but when I fill out the form I get the first variable and then [object HTMLInputElement] for the other variables:

    function insert(){
    var studentId = document.getElementById('student').value;
    var firstName = document.getElementById('first').value;
    var lastName = document.getElementById('last').value;
    var phone = document.getElementById('tel').value;

    var studentRecord = studentId + first + last + tel; //used to store a student record

    alert(studentRecord);
    }

    Or is there a different way to place these values into 1 variable with JavaScript?

  2. #2
    SitePoint Guru
    Join Date
    Sep 2006
    Posts
    731
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think you just need to look a bit more closely at what you've done - even a layman should see the inconsistency.
    Tab-indentation is a crime against humanity.

  3. #3
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hint: you have named your value variables firstName, lastName and phone, but you are using first, last and tel in the concatenation.
    Birnam wood is come to Dunsinane


Bookmarks

Posting Permissions

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