Acquiring the input from a text box to generate a hyperlink on the current page

I am trying to generate a link that has the href attribute as follows:

app\process?val=12000

The catch is that the value for the val parameter (in this case 12000) needs to be derived from a textbox on the page.

I am aware that I can retrieve the value using $(#textbox).value(), but I also need to update the link whenever the value in the textbox changes.

Answer №1

Check out this EXAMPLE of something you might want to experiment with.

Here's the HTML code snippet:

<input type="text" id="text"></input>
<button type="button" id="button">Get Link</button>
<br/>
<a href="#">Test Link</a>

And here's the jQuery code snippet:

$("#button").on("click", function(){
    param = $("#text").val();
    alert("www.example.com\apps?val=" + param);
    $("a").attr("href", "www.example.com\apps?val=" + param);
});​

Just a note regarding the code snippet, in the original post, there was $(#textbox).value(), but that's not quite right. The correct format should be $("#textbox").val(), where "textbox" is the ID of the element. Additionally, remember that in jQuery, it's .val() instead of .value().

Answer №2

<span id="anchor">click here to go to the page </span>


$('#input').on('input', function(){
    $('#anchor').attr('href', 'app\update?value=' + this.value);
});

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

Transforming the jQuery tooltip to be shown in a column layout

Hello, I am currently using the displayTag library to showcase some tables. My goal is to include a tooltip on each display:column element by utilizing jQuery. Below is the code snippet in question: <c:set var="titleName"><wp:i18n key="FILENAME" ...

What is the best way to extract information from a JavaScript page when the content is identified by a reference?

If you're looking for the website, you can visit . It's primarily in Chinese, but that may not be relevant to the topic at hand. Currently, I am able to extract all the content from this page and now I'm interested in moving on to the next ...

What is the process for implementing Autocomplete in JsHelper?

Is it possible to create an Ajax Autocomplete using only pure JsHelper in JavaScript? Thank you, Celso ...

Create a function that adds a new div element with a one-of-a-kind identification when

I am currently developing a web application on www.firstusadata.com/cash_flow_test/. The functionality involves two buttons that add products and vendors dynamically. However, the issue I'm facing is that the appended divs do not have unique IDs, maki ...

Update the website URL in the browser using jQuery

Here is my code for making AJAX requests in my app: $(document).ready(function () { $('ul#ui-ajax-tabs li:first').addClass('selected'); $('#ui-ajax-tabs li a').click(function (e) { e.preventDefault(); ...

Visiting a randomly generated URL will only occur if a certain class is present on that page

Imagine this scenario: I am trying to navigate to a random page by using a function that generates a random URL. However, if the page does not have an image with the class "hello", I will not load it. Instead, I will continue using the function for a ran ...

Can JQuery be used to specifically target attributes with vendor prefixes?

Is there a way to change the Thumb color for my slider without needing to select the thumb with a vendor prefix? I want to be able to dynamically pick the color without simply appending a class. $('.button').on('click', function (e) { ...

attempting to retrieve the selected values from within an iframe

I'm attempting to access the values of an iframe element select within a dialog on my page. In my JS file, I wrote code to access a select with the ID "firstSelectms2side__sx", but it didn't work as expected. Setting aside the iframe, I also tr ...

Transferring information from Vue Component to Vuex storage

I am currently working with a Laravel API route that looks like this: Route::get('c/maintenances/{contractor_user_id}', 'Maintenance\Api\ApiContractorMaintenanceController@index'); The contractor_user_id parameter is dynamic ...

Retrieve the initial element of a JavaScript array

Is there a way to retrieve the first element of a JavaScript array without using array[0]? Interestingly, the array being passed into the method seems to have its first (and only) element stored at index 5 instead of 0. Update - I've attempted to cr ...

JavaScript Error: Unable to determine the value of a null property

Is there a way to validate the user's input in real-time on an HTML form? Take a look at the following HTML code: <div class="col-md-2"> <input class="form-control" name="nbequipement" id="nbequipement" placeholder="" type="text"> ...

Spinning Global Lighting and Bouncing in three.js

I am trying to create a 3D object that automatically rotates around the Y axis while still allowing users to scale and custom rotate the object with their mouse. This is what I have so far: import * as THREE from 'three'; import { GLTFLoader } f ...

Leveraging the node CLI tool as a library for trimming MP3 files (trimp3

I recently came across a fantastic library that I am interested in using for my nodejs project: https://github.com/kyr0/trimp3 The only issue is that it functions as a cli tool, and I would like to integrate it seamlessly into my codebase as a library. D ...

Transform an array of strings into an array of floating point numbers using AngularJS

Hey everyone! I'm having trouble converting an array of strings into floats. When using map(parseFloat), I'm only getting integer numbers. Could the issue be with the commas in 40,78 causing parseFloat to interpret it as 40 instead of 40.78? Her ...

Error encountered: Firebase cloud function in Node.js V10 has experienced a parsing issue due to an unexpected token 'select

Each time I try to deploy my cloud function, I encounter a Parsing error: Unexpected token selectWinner. I attempted to resolve this by updating the parser options in .eslintrc.json to utilize ecmaVersion 2017, but unfortunately, that did not solve the is ...

Controlling worldwide modules using Node Version Manager

Currently, I am utilizing nvm as a tool to manage node.js / io.js versions, encountering difficulties with global modules every time I update node. Recently, I attempted to install npm i express-generator -g. I noticed an older version in /usr/local/bin a ...

When incorporating a Textarea element within styled components in ReactJS, it causes the text to be inputted backwards due to the cursor

Currently, I am utilizing the Textarea component from react-textarea-autosize along with using styled from styled components. In a class, I have created a function called renderForm which is responsible for rendering a form containing a StyledTextarea. How ...

Combine the values of two numbers and then proceed to multiply them by another number with the help of

I am attempting to perform calculations on three numbers - adding two of them and then multiplying the result by the third number every time a key is pressed in one of the input fields. I am using PHP and Ajax to achieve this functionality. Below are snipp ...

Developing a Fresh Settings Tab and Vue Module in Laravel Spark

When working with Laravel Spark, you'll find that most settings panels come with a corresponding Vue JS component that is called upon using a custom tab. <spark-create-tests :user="user" inline-template> <div> </div> </sp ...

How come the array's length is not appearing on the browser screen?

Code: initialize: function() { this.todos = [ {id: 100, text: 'Rich'}, {id: 200, text: 'Dave'} ]; }, activeTodos: function() { this.todos = this.todos.length(function() { return this.todos; }); ...