What steps do I need to take to build this jump page?

Disclaimer: I have very little experience with coding. As a self-taught graphic designer, I have only managed to create a simple page that helps me store common phrases I use frequently throughout the day. It was quite a challenge for me.

I am currently working on a project where users can input text into a field, which will then be applied to predefined URLs linked to buttons that direct them to specific pages. For a visual reference, please check out this image: https://i.sstatic.net/ZplRK.jpg

I have attempted to modify some scripts for similar functionalities, but unfortunately, I haven't had much success. (You can find these examples below before my modifications). I'm including them here to see if I am headed in the right direction at all. I anticipate running into issues with multiple functions eventually?

<script type="javascript">
function goToPage(var url = '')
{
    var initial = "http://example.com";
    var extension = "html";

    window.location(initial+url+extension);
}
</script>

<form name="something" action="#">
Label <input type="text" name="url" value="" onchange="goToPage(this.value)">
</form>

<SCRIPT type="javascript">
function goToPage(var url = '')
{
var initial = "https://cms.example.com/client/viewcasedetails";
var extension = "";

window.location(initial+url+extension);
}
</SCRIPT>
<TITLE>Redirect 1</TITLE>
<BASE HREF="https://cms.example.com/client/viewcasedetails">
</HEAD>
<BODY>
<P>
<FORM name="jump" action="#">
CMS ID:
<INPUT type="text" name="url" value="" onSubmit="goToPage(this.value)">
<INPUT type="submit" value="GO">

This is my current progress. I am tired of manually typing out lengthy URLs all day at work and making mistakes half the time. I'm unsure whether the solution lies in Javascript, HTML, or CSS. I want to explore a do-it-yourself solution before considering hiring someone to develop it for me. However, I am also uncertain about how to go about hiring someone for such tasks, but that's a question for another time.

Thank you for any assistance provided, and I apologize for any seemingly naive questions.

Answer №1

One way to implement this functionality is by using the code snippet below:

// locate the input element
const inputField = document.getElementById("cmsId");

// find all the links that need updating based on the input value
const linksToUpdate = document.querySelectorAll("a");

// create an event listener to track changes in the input field
inputField.addEventListener("input", (event) => {
  // retrieve the current value from the input field
  const textValue = event.target.value;

  // loop through each link and update the displayed text and href attribute accordingly
  // the base URL for each link is stored as a data attribute
  linksToUpdate.forEach((link) => {
    const baseUrl = link.dataset.url;
    const updatedUrl = baseUrl + textValue;

    link.innerText = updatedUrl;
    link.href = updatedUrl;
  });
});
<!-- Simply use an input element without the need for a form -->
<div>CMS ID: <input id="cmsId" type="text" /></div>

<div>
  <!-- Instead of buttons, anchor elements work effectively -->
  <a
    id="main"
    href="#"
    target="_blank"
    data-url="https://cmss.company.com/client/viewclientdetails/"
  >
    https://cmss.company.com/client/viewclientdetails/
  </a>
</div>
<div>
  <a
    id="notes"
    href="#"
    target="_blank"
    data-url="https://cmss.company.com/client/viewnotes/"
  >
    https://cmss.company.com/client/viewnotes/
  </a>
</div>
<div>
  <a
    id="docs"
    href="#"
    target="_blank"
    data-url="https://cmss.company.com/client/documentsall/"
  >
    https://cmss.company.com/client/documentsall/
  </a>
</div>
<div>
  <a
    id="activity"
    href="#"
    target="_blank"
    data-url="https://cmss.company.com/client/viewactivityledger/"
  >
    https://cmss.company.com/client/viewactivityledger/
  </a>
</div>

Answer №2

Your code currently focuses on the "main" button, which directs to viewclientdetails. An important correction is to add a "/" after var initial. By extending this functionality to other buttons, you can achieve the desired outcome:

<script type="text/javascript">
function goToPage(var url = '')
{
var initial = "https://cms.example.com/client/viewcasedetails/"; //Include the slash 

var extension = "";

window.location(initial+url+extension);
}
</script>
<TITLE>Redirect 1</TITLE>
<BASE HREF="https://cms.example.com/client/viewcasedetails">
</HEAD>
<BODY>
<P>
<FORM name="jump" action="#">
CMS ID:
<INPUT type="text" name="url" value="" onSubmit="goToPage(this.value)">
<INPUT type="submit" value="GO"> //Ensure there are 4 buttons

Avoid using an input type="submit" since four buttons are required. Instead, assign onClick functions for each button to specify the redirect URL based on user input.

The following example demonstrates how this can be achieved:

    <script type="text/javascript">
    function onMainButtonClicked()
    {
    var cmsid= document.getElementById("cmsID").value;
    var initial = "https://cms.example.com/client/viewcasedetails/"; //Include the slash 
    
    var extension = "";
    
    window.location(initial+cmsid+extension);
    }
    function onNotesButtonClicked()
    {
    ...
    }
    function onDocsButtonClicked()
    {
    ...
    }
    function onActivityButtonClicked()
    {
    ...
    }
    </script>
    <TITLE>Redirect 1</TITLE>
    <BASE HREF="https://cms.example.com/client/viewcasedetails">
    </HEAD>
    <BODY>
    <P>
    <FORM name="jump" action="#">
    CMS ID:
    <INPUT type="text" id="cmsID" name="url" value="">
    <button onclick="onMainButtonClicked()">Main</button>
    <button onclick="onNotesButtonClicked()">Notes</button>
    <button onclick="onDocsButtonClicked()">Docs</button>
    <button onclick="onActivityButtonClicked()">Activity</button>

While there are more advanced methods available, this simple implementation serves its purpose effectively.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Strange occurrences observed on array mapping post-state alteration

Greetings to all during these challenging times! Currently, I am delving into Firebase and ReactJS and have encountered a peculiar issue involving state updates in React and the array map functionality in JavaScript. Below is the code snippet showcasing my ...

Can Hapi-Joi validate a payload consisting of either an Array of objects or a plain Javascript object?

How can I create a schema to validate payloads for a post call that accepts either a single JS object or an array of objects to be saved in the database? JS object { label: 'label', key: 'key', help_text: 'text' } ...

What could be causing the malfunction of material-UI Tabs?

My Material UI Tabs seem to have stopped working after a recent update. I suspect it may be related to the react-tap-event-plugin update I installed. Initially, I thought it was due to tab indexing but even using values like value='a', value=&apo ...

What is the best way to add data to my collection using the main.js file on the server side in a Meteor application

I am a beginner with Meteor and trying to customize the tutorial codes. I have a code that listens for packets on my server-side main.js. Now, I need to store the data printed on the console into my database collection. import { Meteor } from 'meteor/ ...

Display two separate views or templates on the screen using AngularJS

Currently, I am developing a mobile app powered by Angular and I am looking to create a unique view that displays halves of two separate views. The user should be able to switch between the two views by swiping up or down. Can anyone provide advice on how ...

Building a drop-right menu with Bootstrap within a dropdown menu - a step-by-step guide

I added a drop-down link to the site's navigation bar, but I'm trying to make one of the drop-down items a dropright link within another drop-down menu in the navigation bar. How can I achieve this? I tried using the code below, but the second d ...

Issue arising from CSS and div elements

I am facing some challenges in making certain divs behave as desired. Take a look at the following references: Link 1: - contains two divs Link 2: - has only one div I am trying to utilize two divs (.content) without them being positioned incorrectly ...

I'm encountering an issue with the React state where it seems to be endlessly nesting

I am new to React and I seem to be encountering an issue where every time I trigger a click event, the state object continues to nest. The code snippet below is part of the App component. const [state, setstate] = useState('') useEffect(() =& ...

Trouble with font sizing in a single line

Here's an interesting problem I encountered: <ol><li> <span>01</span><h4>SOME TEXT</h4> </li></ol> #faq ol li h4 { padding-bottom: 16px; padding-top: 14px; padding-left: 16px; max ...

The pairing of Transpiller and Internet Explorer 8 is like a dynamic

In starting my new project, I am considering using BabelJS. However, there is a significant requirement that must be met: it needs to be compatible with IE8. ISSUE: Babel compiles ES6 to ES5, but the support for ES5 on IE8 is lacking. Are there any alter ...

How can you generate a "Package Contains Lower Node Version" error message during the installation of an NPM package if the node version is higher than the current system's node version?

I am looking for a way to trigger an error during the installation of an NPM package if the node version supported by that module does not match the system/server node version. Specifically, I want to prevent the installation of any npm module that suppor ...

Send an Ajax request to the controller and retrieve a file to display in an iframe

I need to display the contents of a byte[] array in an Iframe and provide the option for the user to download the file in PDF format. My view has a button connected to an ajax call that sends the byte[] to my actionresult, which returns a FileContentResul ...

Deleting multiple subdocuments and their related subdocuments with Mongoose

In my application, I have a Project document that contains an array of subdocuments structured as Tasks. Each Task has its own array of subdocuments with a schema called Comments. const projectSchema = new Schema({ _id: Schema.Types.ObjectId, name: { ...

Employ jquery to exclusively add either a beginning tag or closing tag

As I continue to learn, I have discovered that using replaceWith('<section>') or after('<section>') results in the full element being inserted in both scenarios: <section></section> Interestingly, when at ...

What is the best way to manage adding and removing table rows in Laravel while also incorporating a dropdown list?

I am trying to add more rows with the same values to a table form that includes a dropdown list generated by a @foreach loop. Here is the code: <tbody> <tr> <td> <select class="form-control" name="roo ...

The onmessage event in the websocket client seems to be malfunctioning and is not triggering

In my implementation using node.js, I have set up a websocket server and client. The handshake process between the server and client appears as follows: Request URL: ws://localhost:8015/ Request Method: GET Status Code: 101 Switching Protocols Request ...

Steering clear of repeating evaluations and dynamically unloading objects requested with `require` is important

I'm currently delving into the intricacies of the nodejs module system. Among the resources I've come across so far are: https://nodejs.org/api/modules.html These readings have shed light on a few aspects, but I still have some lingering ques ...

The functionality of the AJAX Script is failing to load properly on mobile devices

Currently, I am undertaking a project that involves ESP32 Arduino programming to create a webpage where users can interact with buttons to activate relays. Additionally, I have implemented a slider using a short script. This project is inspired by the ESP3 ...

Tips for enabling file uploads with the same name using jQuery.filer

Currently, I have implemented the jquery.filer plugin for handling file uploads on my webpage. While the plugin is functioning correctly, I have encountered an issue where if I attempt to upload the same file a second time, it fails to upload without displ ...

What could be the reason my Backbone view is failing to render?

Can anyone help me troubleshoot why this template isn't rendering properly in my backbone views? Any insights would be greatly appreciated! Below, I've included the code from my jade file for the views and the main.js file for the backbone js scr ...