The page on the server called by the JavaScript is a PHP file called
GetHint.php
, which checks an array of course titles, and returns the corresponding title(s) to the browser.
If there is any text sent from the JavaScript (strlen($q)>0
), the following happens:
txtHint
placeholder.
<?php // Fill up array with course titles. $a[] = "160 Computer Science I"; $a[] = "161 Computer Science II"; $a[] = "230 Systems Programming"; $a[] = "242 Algorithms and Data Structures"; $a[] = "289 Social Implications of Computer Technology"; $a[] = "363 User Interface Design"; $a[] = "365 Organization of Programming Languages"; $a[] = "451 Operating Systems I"; $a[] = "457 Electronic Commerce Systems"; $a[] = "465 Principles of Translation"; $a[] = "Chem121 General Chemistry I"; $a[] = "Chem122 General Chemistry II"; $a[] = "Comm110 Fundamentals of Public Speaking"; $a[] = "EE201 Introduction to Digital Electronics"; $a[] = "EE202 Electrical Engineering Laboratory"; $a[] = "Engl110 College Composition I"; $a[] = "Engl130 Composition II: Writing for Public Audiences"; $a[] = "Math146 Applied Calculus I"; $a[] = "Math165 Calculus I"; $a[] = "Math166 Calculus II"; $a[] = "Math208 Discrete Mathematics"; $a[] = "Math321 Applied Statistical Methods"; // Get the q parameter from URL. $q = $_GET["q"]; // Look up all hints from array if length of q > 0. if ( strlen($q) > 0 ) { $hint = ""; for ( $i=0; $i<count($a); $i++ ) if ( strtolower($q) == strtolower( substr( $a[$i], 0, strlen($q) ) ) ) if ( $hint == "" ) $hint = $a[$i]; else $hint = $hint . ", " . $a[$i]; } // Set output to "no suggestion" if no hint were found // or to the correct values. if ( $hint == "" ) $response = "No suggestion"; else $response = $hint; // Output the response. echo $response; ?> |
When I finished high school, I wanted to take my graduation money and buy myself a motorcycle, but my mom said no. See, she had a brother who died in a horrible motorcycle accident when he was eighteen. And I could just have his motorcycle. — Riki Lindhome, quoting Anthony Jeselnik |