Commit 0a501963 authored by Zac Wood's avatar Zac Wood

Added search by CRN on homepage

parent 5de61c75
function search() {
const searchTable = document.getElementById('scheduleTable');
const crn = document.getElementById('search').value;
fetch(`api/search?crn=${crn}`)
.then(section => section.json())
.then(section => addRow(searchTable, section));
}
function addRow(table, section) {
const tr = document.createElement('tr');
const fields = [section.name, section.title, section.crn, section.professor, section.location, section.days];
fields.forEach(field => {
const td = document.createElement('td');
const txt = document.createTextNode(field);
td.appendChild(txt);
tr.appendChild(td);
});
table.appendChild(tr);
}
<h1>Schedules</h1>
<input type="text" title="search_text" placeholder="Enter CRN..."/>
<button title="search">Search</button>
<input type="text" id="search" title="search_text" placeholder="Enter CRN..."/>
<button title="search" onclick="search()">Search</button>
<!-- <h2>Search results</h2>
<table id="searchTable">
<tr>
<th>Course</th>
<th>Section Name</th>
<th>CRN</th>
<th>Professor</th>
<th>Location</th>
<th>Days</th>
<th>Times</th>
</tr>
</table>
-->
<!-- <br><br> -->
<h2>Your classes</h2>
<table>
<table id="scheduleTable">
<tr>
<th>Course</th>
<th>Section Name</th>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment