Note that there are some explanatory texts on larger screens.

plurals
  1. POsyntax error else {, what does it mean?
    primarykey
    data
    text
    <p>I dont quite this syntax error I am having when it keeps saying else { in code below:</p> <pre><code>$(document).ready(function () { var courseinfo = &lt;?php echo json_encode($courseInfo);?&gt; ; $('#coursesDrop').change(function () { var courseId = $(this).val(); /* You only need to do all of this if user selects a course, so check that first. */ if (courseId !== '') { /* Iterate over courses and, if the one we want exists, populate its info. */ for (var i = 0, l = courseinfo.length; i &lt; l; i++) { if (courseinfo[i].CourseId == courseId) { $('#currentDuration').val(courseinfo[i].Duration); $('#newDuration').val(courseinfo[i].Duration); $('#currentCourseId').val(courseinfo[i].CourseId); $('#newCourseId').val(courseinfo[i].CourseId); var text = $(this).find('option:selected').text(); var split = text.split(' - '); $('#currentCourseNo').val(split[0]); $('#currentCourseName').val(split[1]); /* Without this break, the loop will continue until i = l. We've already found our match, no need to continue. */ break; } } } else { $('#currentCourseNo,#currentCourseName,#currentDuration,#currentCourseId').val(''); } }); }); </code></pre> <p>Brackets seems correct but why am I getting this syntax error for the code above?</p> <p>The exact error says <code>Syntaxerror: syntax error</code> and then in the view page source it just higlights this <code>else{</code>.</p> <p><code>var courseinfo = &lt;?php echo json_encode($courseInfo);?&gt; ;</code> outputs this below in page source:</p> <pre><code>var courseinfo = [{"CourseId":1,"CourseNo":"INFO101","CourseName":"Bsc Information Communication Technology","Duration":"4"},{"CourseId":2,"CourseNo":"INFO102","CourseName":"Bsc Computing","Duration":"3\/4"},{"CourseId":8,"CourseNo":"INFO103","CourseName":"Business and Finance","Duration":"3"},{"CourseId":9,"CourseNo":"INFO107","CourseName":"Mathematics","Duration":"4"}]; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload