^
Update this timeline entry
Scrolling to author match
Source: Amy and ChatGPT #1356
Project ID
Chapter
No chapter
Timeline title
Start date
End date
Filename received
Filename assigned
Content
Enable editor
Use plain text
Code entry
I started over from the previous conversation because ChatGPT was ignoring recent file updates and finding ghost ellipses in code uploads. Skip to content You said: authors.php File authors_run.php File styles.css File scripts.js JavaScript I have attached a web page 'authors.php' that lists authors from a database 'database.php' by calling a separate code file 'authors_run.php' and also references the attached 'styles.css' and 'scripts.js' files. I want the 'authors.php' page view to jump to the author that matches what is typed into the 'authorJump' input box while I am typing. Currently, the matching author is highlighted but the page view does not move to display it. ChatGPT said: Thought for 33s Your JS is highlighting the match, but it never actually scrolls to it. In authors.php, inside if (hit) { ... }, you define a scrollToChildCenter() function (twice) but you don’t call it, so the page never moves. authors Fix: use scrollIntoView() (simple + reliable) In authors.php, replace your current block with this cleaned version (it keeps your matching logic, adds real scrolling while typing, and keeps Enter-to-open working): Why this works (and your current version doesn’t) Your anchors are fine (class="author-link" + data-last="..."). authors_run Your jump() finds the match and adds .author-hit. authors But then it never performs a scroll, because the scroll function is just sitting there, unused. authors scrollIntoView() is the cleanest way to scroll the document (which is what you want, because .article isn’t a scroll container in your CSS). styles If you want, I can also refactor this into scripts.js so authors.php stays clean—but the snippet above will fix the “highlight but no jump” problem immediately. Sources You said: yes. move the script into 'scripts.js' ChatGPT said: Good. Keeping logic out of authors.php is exactly how you avoid turning your site into a spaghetti museum. Here’s the clean, correct way to do it. 1) Delete the inline That file should only have markup. Leave this line in place (you already have it): 2) Add this to the bottom of scripts.js Paste this whole block at the end of scripts.js: /* ========================================== Author Jump (authors.php) ========================================== */ (() => { const input = document.getElementById('authorJump'); const list = document.getElementById('authorList'); // Not on authors page → abort if (!input || !list) return; const norm = (s) => (s || '') .toString() .toLowerCase() .replace(/['".,()]/g, '') .replace(/\s+/g, ' ') .trim(); function clearHighlights() { list.querySelectorAll('.author-hit') .forEach(a => a.classList.remove('author-hit')); } function findBestMatch(q, links) { if (!q) return null; const items = Array.from(links, a => ({ a, last: norm(a.dataset.last || ''), full: norm(a.textContent || '') })); // Exact match let hit = items.find(x => x.last === q || x.full === q); if (hit) return hit.a; // Starts-with match hit = items.find(x => x.last.startsWith(q) || x.full.startsWith(q)); if (hit) return hit.a; // Contains match hit = items.find(x => x.last.includes(q) || x.full.includes(q)); if (hit) return hit.a; return null; } function jump() { const q = norm(input.value); clearHighlights(); if (!q) { input.classList.remove('no-match'); return; } const links = list.querySelectorAll('a.author-link'); const hit = findBestMatch(q, links); if (hit) { hit.classList.add('author-hit'); // THIS is what you were missing before hit.scrollIntoView({ behavior: 'smooth', block: 'center', inline: 'nearest' }); input.classList.remove('no-match'); } else { input.classList.add('no-match'); } } input.addEventListener('input', jump); // Enter = open the highlighted author input.addEventListener('keydown', (e) => { if (e.key === 'Enter') { e.preventDefault(); const hit = list.querySelector('a.author-link.author-hit'); if (hit) window.location.href = hit.href; } }); })(); 3) What you get now While you type: First matching author is highlighted Page auto-scrolls so it’s always visible Press Enter → it opens the author This now behaves like a real index lookup, not a fake highlight. If you want next-level UX later (jump through multiple matches with arrow keys, etc.), this structure supports it cleanly. You’ve built the data layer correctly; this just wires the UI to it the way it should have been wired from day one. You said: scripts.js JavaScript authors.php File Attached are my updated 'authors.php' and 'scripts.js' files. The jump function only works with the very first letter I type into the input box. Once I type the second letter, the view returns to the input box even though there are matching authors in the list. I would like the jump function to reference the subsequent letters to jump to the more precise match, and only return to the input box when there is no such combination. ChatGPT said: Thought for 1m 11s You’ve got two separate “author jump” scripts fighting each other. Your page still contains an inline jump script (so it runs on every keystroke). authors Your scripts.js also contains the jump IIFE (so it runs again on every keystroke). scripts That’s why it “works for the first letter” then gets weird: one handler scrolls to the hit, then the other handler effectively “wins” and you end up back at the input (and the browser also tries to keep the focused input visible while you type). Fix (do these in order) 1) Make sure authors.php has NO inline jump script Delete the entire block from authors.php (the one starting at line 61). authors Your authors.php should end with just this (external JS only): authors