Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8958971
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T15:20:24+00:00 2026-06-15T15:20:24+00:00

I dont quite this syntax error I am having when it keeps saying else

  • 0

I dont quite this syntax error I am having when it keeps saying else { in code below:

$(document).ready(function () {

    var courseinfo = <?php echo json_encode($courseInfo);?> ;

    $('#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 < 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('');
        }
    });
});

Brackets seems correct but why am I getting this syntax error for the code above?

The exact error says Syntaxerror: syntax error and then in the view page source it just higlights this else{.

var courseinfo = <?php echo json_encode($courseInfo);?> ; outputs this below in page source:

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"}];
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T15:20:25+00:00Added an answer on June 15, 2026 at 3:20 pm

    I can’t sure the problems are located …
    Because you don;t show any html line …
    But would you like to try this code:

    $(function(){
    var courseinfo = <?php echo json_encode($courseInfo);?>;
    $('#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 (i = 0;i < courseinfo.length;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('');
        }
        });
    });
    

    If it won’t work, i say sorry okay ….
    Good luck

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im using Doctrine and i dont quite understand this code here: $this->hasColumn('id', 'integer', 8,
I'm quite new to PHP so I don't know how to solve this error.
So, I get this error message: EDT ERROR: syntax error at or near union
I don't quite understand the \ and \.. syntax in the compile error I'm
Have a look a this simple example. I don't quite understand why o1 prints
This is probably quite simple, but I just don't know how to do this...
I don't quite understand how Google Maps 's google.maps.LatLngBounds.isEmpty function works. What defines a
I'm really quite frustrated at this point. I have an existing hg repository that
I was under the impression this is valid SQLite syntax: SELECT *, (SELECT amount
My apologies, I've actually asked this question multiple times, but never quite understood the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.