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

  • SEARCH
  • Home
  • 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 8937865
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T10:29:23+00:00 2026-06-15T10:29:23+00:00

Hi when I open up the application (code is at bottom of question), straight

  • 0

Hi when I open up the application (code is at bottom of question), straight away I get an error stating:

SyntaxError:missing ; before statement

The above error shows this line in the view page source:

var moduleinfo = 
Notice: Undefined variable: moduleInfo in ... on line 267

How can the above error be fixed?

Also in the code below when the user selects a course from the course drop down menu and submits the course, it displays a modules drop down menu but it also gives me another error stating:

ReferenceError: validation is not defined

The above error shows that this error is in line 1 in the page source which is just a blank line.

My question is that how can both these errors be fixed in the code below:(The order of the code below is the exact order in the application with the php coming first then the javascript, I have also commented on where line 267 is (javascript) for first error and commented where javascript function validation is)

PHP/HTML

<?php

// connect to the database
include('connect.php');
include('noscript.php');

/* check connection */
if (mysqli_connect_errno()) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    die();
}


$sql = "SELECT CourseId, CourseNo, CourseName FROM Course ORDER BY CourseNo";

$sqlstmt = $mysqli->prepare($sql);

$sqlstmt->execute();

$sqlstmt->bind_result($dbCourseId, $dbCourseNo, $dbCourseName);

$courses = array(); // easier if you don't use generic names for data 

$courseHTML = "";
$courseHTML .= '<select name="courses" id="coursesDrop">' . PHP_EOL;
$courseHTML .= '<option value="">Please Select</option>' . PHP_EOL;

$outputcourse = "";
$hiddencourse = "";

while ($sqlstmt->fetch()) {
    $course     = $dbCourseId;
    $courseno   = $dbCourseNo;
    $coursename = $dbCourseName;
    $courseHTML .= "<option value='" . $course . "'>" . $courseno . " - " . $coursename . "</option>" . PHP_EOL;

    if (isset($_POST['courses']) && ($_POST['courses'] == $course)) {
        $outputcourse .= "<p><strong>Course:</strong> " . $courseno . " - " . $coursename . "</p>";
        $hiddencourse .= "<p><input type='hidden' id='hiddencourse' value='" . $courseno . " - " . $coursename . "'></p>";
    }

}

$courseHTML .= '</select>';


?>

<form action="<?php
echo htmlentities($_SERVER['PHP_SELF']);
?>" method="post" onsubmit="return validation();">
<table>
<tr>
<th>Course: <?php
echo $courseHTML;
?></th>
</tr>
</table>
<p><input id="courseSubmit" type="submit" value="Submit Course" name="courseSubmit" /></p>
<div id="courseAlert"></div>
<div id="targetdiv"></div>
</form>

<?php

if (isset($_POST['courseSubmit'])) {
    //get the form data 
    $coursesdrop = (isset($_POST['courses'])) ? $_POST['courses'] : '';

    $modulequery = "
SELECT
m.ModuleId, m.ModuleNo, m.ModuleName, m.Credits
FROM
Module m
WHERE
m.ModuleId NOT IN (
SELECT cm.ModuleId
FROM Course_Module cm
WHERE cm.CourseId = ?
)
ORDER BY m.ModuleNo
";

    $moduleqrystmt = $mysqli->prepare($modulequery);
    // You only need to call bind_param once
    $moduleqrystmt->bind_param("i", $coursesdrop);
    // get result and assign variables (prefix with db)

    $moduleqrystmt->execute();

    $moduleqrystmt->bind_result($dbModuleId, $dbModuleNo, $dbModuleName, $dbCredits);

    $moduleqrystmt->store_result();

    $modulenum = $moduleqrystmt->num_rows();

    $moduleHTML = '<select name="module" id="modulesDrop">' . PHP_EOL;
    $moduleHTML .= '<option value="">Please Select</option>' . PHP_EOL;

    $moduleInfo = array();

    while ($moduleqrystmt->fetch()) {
        $moduleHTML .= sprintf("<option value='%s'>%s - %s</option>", $dbModuleId, $dbModuleNo, $dbModuleName) . PHP_EOL;

        $moduleData               = array();
        $moduleData["ModuleId"]   = $dbModuleId;
        $moduleData["ModuleNo"]   = $dbModuleNo;
        $moduleData["ModuleName"] = $dbModuleName;
        $moduleData["Credits"]    = $dbCredits;

        array_push($moduleInfo, $moduleData);

    }


    $moduleHTML .= '</select>';


    $moduleexist = "
<div id='rt-container'>
<form id='moduleExistForm'>
<p><strong>Current Modules</strong></p>
<p>{$moduleSELECT}</p>
</form> 
</div>";

    echo $moduleexist;


}

?>

Javascript

<script type="text/javascript">
    $(document).ready(function () {

        var moduleinfo = <?php echo json_encode($moduleInfo); ?> ; //line 267

        $('#modulesDrop').change(function () {

            var moduleId = $(this).val(),
                moduledata;

            for (var i = 0, l = moduleinfo.length; i < l; i++) {
                if (moduleinfo[i].ModuleId == moduleId) {
                    moduledata = moduleinfo[i];
                }
            }

            var currentindex = $('#credits').val(moduledata.Credits);

        });


    });

//below is the validation() function

    function validation() {

        var isDataValid = true;

        var courseTextO = document.getElementById("coursesDrop");

        var errCourseMsgO = document.getElementById("courseAlert");

        if (courseTextO.value == "") {
            $('#targetdiv').hide();
            $('#moduleForm').hide();
            $('#detailsForm').hide();
            $('#addbtn').hide();
            errCourseMsgO.innerHTML = "Please Select a Course";
            isDataValid = false;
        } else {
            errCourseMsgO.innerHTML = "";
        }

        return isDataValid;

    }
</script>
  • 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-15T10:29:24+00:00Added an answer on June 15, 2026 at 10:29 am

    Remove the space in your php line:

    var moduleinfo = <? php echo json_encode($moduleInfo); ?> ;

    To

    var moduleinfo = <?php echo json_encode($moduleInfo); ?> ;

    <? php should be together like <?php

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

Sidebar

Related Questions

currently i using this code in phonegap application var xmlhttp = new XMLHttpRequest(); xmlhttp.open(GET,http://192.168.1.19:8080/searchMobile?categoryRequest=true,
I have built an open-source application from the source code. Unfortunately, the original executable
In my application i need to open pdf file.For that i have prepared code
I have the following code to open a browser in Perl $IE = Win32::OLE->new(InternetExplorer.Application);
Hello to open Application from URL i have code below <intent-filter> <action android:name=android.intent.action.VIEW></action> <category
var doc = w.document; doc.open('application/CSV','replace'); doc.charset = utf-8; doc.write(all,hello); doc.close(); if(doc.execCommand(SaveAs,null,file.csv)) { window.alert(saved );
When we open NUnit application it loads the assemblies that are loaded in it
How would you open your application directly using an intent filter when using the
I'm converting a open-source application from C to Delphi, but I'm having problems converting
I have created a facebook website open graph application for my website www.heyngine.com. 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.