1

I keep getting this error in my code and I don't understand why. See line 29 of my Javascript.

HTML

<link href="Styles12.css"; type="text/css" rel="stylesheet">
<link rel="stylesheet" href="Styles12.css"/>
<script src="registration.js"></script>
<body onload="studentAttendance()">
    <head>
        <style>
           table, td, th {
               border: 1px solid black;
           }
            th {
                background-color: beige;
                color:black;
            }
        </style>
    </head>
<h3 style= "font-size:25px; font-family:Impact"> ADD A STUDENT</h3>

Firstname:

Lastname:

Student number:

    <button onclick = "save()"><p>+ADD TO ATTENDANCE</a></p> </button>
    <h2 style="font-size: 25px;font-family: Impact">Online attendance</h2>    
    <table id= "attendanceTable">
        <table border="10px">
            <thead>
                <tr>
                    <th> Student Name </th>
                    <th> Student Number </th>
                    <th> A </th>
                    <th> Points </th>
                    <th style="font-size:10px;font-align: left"><em><button> Edit:Add student(+)</a></button></em></th>
                    </th>
                 </tr>
            </thead>
    <tbody>
        <tr>
            <td></td>
            <td></td>
            <td><form action="demo_form.asp" method="get"></form></td>
            <td></td>
           <td> <input type="button" value="save"></input>
        <button>reset</button></td>
        </tr>
        <tbody>
            <tr>
                <td></td>
                <td></td>
                <td><form action="demo_form.asp" method="get"></form></td>
                <td></td>
            </tr>
            <tbody>
                <tr>
                    <td></td>
                    <td></td>
                    <td><form action="demo_form.asp" method="get"></form></td>
                    <td></td>
                </tr>
            </tbody>
        </table>

    <form>
    </form> 
    <button type="button" onlick="alert('Attendence submitted')">  <strong>SUBMIT</strong></button>
    <p id="demo"></p>
</body>

JAVASCRIPT

var studentNo = [];
var index = 0;
var studentInfo = [];
var newObj = [];

function save() { //this function takes values from the text box and stores them as an object studentInfo[index] = { studentNumber: document.getElementById("studentNo").value, firstname: document.getElementById("firstname").value, lastname: document.getElementById("lastname").value, }; index++;

    localStorage.setItem("studentRecord", JSON.stringify(studentInfo));
}

function studentAttendance() {
    newObj = JSON.parse(localStorage.getItem("studentRecord"));
    var table, row, cell1, cell2, cell3;
    table = document.getElementById("onlineAttendance");
    studentInfo = JSON.parse(localStorage.getItem("studentRecord"));
    for (var index = 0; index < studentInfo.length; index++) {
        row = table.insertRow(index + 1);
        cell1 = row.insertCell(0);
        cell2 = row.insertCell(1);
        cell3 = row.insertCell(2);
        cell4 = row.insertCell(3);
        cell1.innerHTML = studentInfo[index].studentNumber;
        cell2.innerHTML = studentInfo[index].firstName + " " +
            studentInfo[index].lastName;
        cell3.innerHTML = studentInfo[index].
        '<input type="checkbox" name="student attendance" value="absent" id="checkboxab"</input>';

    }

    function save() {
        if (document.getElementById('checkboxab').checked) {
            alert("checked");
        } else {
            alert("You didnt check it")
            studentInfo.points++
        }
    }
}
2
  • 1
    Something is wrong here: cell3.innerHTML = studentInfo[index]. '<input type="checkbox" name="student attendance" value="absent" id="checkboxab"</input>'; Commented Jun 14, 2015 at 2:19
  • 3
    The syntax error is obvious. You are using dot syntax with string Commented Jun 14, 2015 at 2:19

3 Answers 3

3

. use in php to concat string

+ use in javascript to concat string

try like this

cell3.innerHTML =studentInfo[index]+
        '<input type="checkbox" name="student attendance" value="absent" id="checkboxab"</input>';
Sign up to request clarification or add additional context in comments.

1 Comment

Can we merge answers? :-) (seriously, i want to create a question on Meta)
2

I think that you are confusing PHP string concatenating with Javascript string concatenating:

PHP

$variable = $other_variable . '<span>hello world</span>'

Javascript

var variable = other_variable + '<span>hello world</span>'

I get it?

Comments

0

The dot is a syntax error. You should use a +.

  cell3.innerHTML = studentInfo[index].
    '<input type="checkbox" name="student attendance" value="absent" id="checkboxab"</input>';

If you don't have another way to validate your JS, put it into a jsfiddle and press JSHint.

http://jsfiddle.net/mgb8x7pd/

2 Comments

It might be less confusing if your code showed the correct version :)
I was trying to illustrate the jshint functionality =\

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.