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 8961885
In Process

The Archive Base Latest Questions

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

Here is my Question: I have a dynamic list that displays X classes. when

  • 0

Here is my Question:

I have a dynamic list that displays X classes. when a class is selected, all the students of the class are displayed. When a user clicks “submit”, I want to send an insert statement to the database. Where does the code for the submit button go?

My Attempt: Pseudocode/structure

Files placed in 1 folder on webserver: Index.php and getStudentList.php

Index.php

<script>
function showStudents(str)
blabla
xmlhttp.open("GET","getStudentList.php?q="+str, true);
xmlhttp.send();
</script>
...
<div>
html display goes here, as well as the form itself
</div>

getStudentList.php

<script>
logic for javascript goes here which connects to a db and inserts attendance info
</script>
<?php
connect to db
query students in class
echo attendance form
?>

Detailed Code:
Index.php

<!--start script for AJAX attendance display-->
<script>
function showStudents(str)
{
if (str=="") {
  document.getElementById("attendanceForm").innerHTML="";
  return;
}
if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
}
else {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}

xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("attendanceForm").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","getStudentList.php?q="+str,true);
xmlhttp.send();
}
<script>
<div>
    <?php
        //identify teacher's classes
        $school_connection = New school();
        $arrayTeachersClasses = $school_connection->queryTeachersClasses($_SESSION['teacherID']);
        //returns array of all classes taught
        //echoes today's date
        echo Date("l F d, Y");
        //create list so teacher can pick class
        echo "<form>";
        echo "<select name = \"courses\" onchange = \"showStudents(this.value)\">";
        echo "<option value=\"\">Select a class:</option>";
        $i = 0;//counter        
        while ($row = $arrayTeachersClasses[$i]) {
            echo "<option value=\"". $row[0] . "\">";
            echo $row[1] . "  ". $row[2] . "-L". $row[3] . " Room " . $row[4];
            echo "</option>";
            $i++;
        }
        echo "</select>";
        echo "</form>";


    /***
    //Sample "Select a Class" list
    <form>
    <select name="users" onchange="function(this.value)">
        <option value="">Select a class:</option>
        <option value="0">09:00:00  BEG-L1 Room303</option>
        <option value="1">TIME SUBJ-LEVEL ROOM</option>
        <option value="2">ditto</option>
        <option value="3">ditto</option>
    </select>
    </form>
    */

        $teacherID = $_SESSION['teacherID'];
        //echo $teacherID;


    ?>
</div>
<br />
<div id="attendanceForm">
    <p><b>Attendance List:</b></p>
    Please Select a Class
</div>

getStudentList.php

<script>
//Other JS stuff
$(document).ready(function() {

    //if submit button is clicked
    $('#submit').click(function () {        

    $i = 0;//counter
    var attendanceData = new Array();
    //Get the data for each student
    while ($row = $arrayStudentList[$i]) {
    var studentID = $('input[name=' . $row[0] . ']');
        if (studentID.val()=='') {
            studentID.addClass('highlight');
            return false;
        } else studentID.removeClass('highlight');

    $row[2] = studentID.val;
    $attendanceData[$i] = $row;
    $i++;
    }

    $row = $attendanceData[0];
    $record = $row[2];
    alert("My First JavaScript");

        //cancel the submit button default behaviours
        return false;
    }); 
}); 
</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-15T15:59:46+00:00Added an answer on June 15, 2026 at 3:59 pm

    there are many ways of doing this…
    Below are 2 simple solutions: with postback or through ajax.

    Options 1 – Postback

    1. when submit is clicked submit the form to the index page itself: leave form action blank or use $_SERVER['PHP_SELF']
    2. in index.php prior to displaying anything check request type & params and save data
    3. generate success/failure message and display

    Option 2 – Ajax

    1. create new page insertStudent.php
    2. Add ajax functionality to form submit and send form to insertStudent.php. see jquery submit or reinvent the wheel for your project
    3. In insertStudent.php save the student and return json status or (1/0)
    4. handle the response in your ajax handler (step 2) to display success/failure message

    Hoe this helps you with your homework 😉

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

Sidebar

Related Questions

Here is my question : I have a huge class (HugeClass) and I wanted
Basic question here - I have many lines of code that look something like:
Here is a question that I have had for some time but never actually
Greetings all, I have a list of Types meeting a certain critera that I
I have a class that uses either a static list (firstFriend in the example)
R newbie question here. I have a list called dbdata . Normally I use
Newbee question here - I have this method in the view controller m: -(void)
here's my question: I have a table TRUST(id INT, trustlevel INT) which contains records
here's my question: I have an MVC3 C# application and I need to update
I have a question here regarding iPhone app submission. I have a free application

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.