Skip to content

Use link updating script that is little more straightforward #10

@yasonk

Description

@yasonk

Instead of

// Change each link to reflect settings
        document.querySelectorAll(".study-guide-link").forEach(link => {
            let subject = link.getAttribute("data-subject");
            let topic = link.getAttribute("data-topic");
            let newUrl = `{{ url_for('study_guide') }}?subject=${encodeURIComponent(subject)}&topic=${encodeURIComponent(topic)}&username=${encodeURIComponent(username)}&teaching_style=${encodeURIComponent(teachingStyle)}`;
            link.href = newUrl;
        });
<input type="text" id="queryField" placeholder="Enter query param value" />
<a href="https://example.com/page2" onclick="handleLinkClick(event)" class="link">Page 2</a>

<script>
  function handleLinkClick(event) {
    event.preventDefault(); // Stop default navigation

    const input = document.getElementById('queryField');
    const value = input.value.trim();
    const url = new URL(event.currentTarget.href);

    if (value) {
      url.searchParams.set('q', value); // Replace 'q' with your param name
    }

    window.location.href = url.toString(); // Navigate to updated link
  }
</script>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions