What is the best way to invoke a new webpage while also incorporating the data from a form variable?

I am looking to create a link that directs to a new page in the following format:

/topic/create&qty=4

Currently, I have the value (which is the number 4) stored in an input field within a form. Initially, I attempted to include everything in the form using POST method but realized this is not the desired approach. I simply want a button click to navigate to a new page and pass the value from the input field. The reason for preferring just a link is that future posts from the form will be handled differently.

Is there a way to achieve this? I understand that

<form action="/adminTopics" method="post">

is not the solution I am seeking.

Answer №1

POST cannot be used to send data through the URL, but you can utilize GET in this manner: /topic/create?qty=4

UPDATE: Explanation

If you input red in the text box and submit it using this form...

<form action="/handler.php" method="GET">
    <input type="text" name="color" />
    <input type="submit" />
</form>

you will receive the same outcome on the server as if you had clicked on this link

<a href='/handler.php?color=red'>rum</a>

Answer №2

When dealing with a URL like /topic/add?quantity=3

that needs to be submitted, you have a couple of options:

<form action="/topic/add" method="post">
<input type="hidden" name="quantity" value="3" />
</form>

<a href="#" onclick="document.forms[0].submit(); return false">Submit</a>

Alternatively, you can use the following script:

<script>
window.onload=function() {
  document.forms[0].submit();
}
</script>

If submitting via POST is not required, simply append the data to the URL for a GET request:

<input id="quantity" type="hidden" name="quantity" value="3" />

<a href="/topic/add"
 onclick="location=this.href+'?quantity='+document.getElementById('quantity').value; 
 return false">Go</a>

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

How can I include one of the three dependent select boxes in my dynamically generated field within a loop?

My jQuery codes are currently functioning only in HTML fields. How can I replicate the same process in my dynamic field? Please refer to the images below. Below is the content of my index.php file for the form: <?php // Include database configurat ...

Is there a way to modify the height and width of a div layer?

How can I adjust the height and width of the layer on the card? Also, I want only the close button to be clickable and everything else to be unclickable. Can anyone help me find a solution? <link rel="stylesheet" href="https://stackpath.bootstrapcdn. ...

Height not being generated by Div element

I am encountering an issue with a div element that contains an h2 and three nested div elements. Despite not explicitly setting a height for the container div, it is not expanding to accommodate the varying heights of the inner divs. This problem is causin ...

Switch the Angular app written in Javascript to Typescript

I am looking to create a pluginable Angular app and came across this tutorial that uses RequireJs for loading scripts in the correct order. Now, I want to convert this project to TypeScript but I am unsure of how to incorporate RequireJs into TypeScript. ...

How can I retrieve columns containing HTML tags in MySQL?

I have a database with columns that contain HTML tags, such as Rot<sub>1</sub> When I run queries like SELECT Rot<sub>1</sub> FROM chem.thermTable; I encounter an error in my SQL syntax. Enclosing the column name in quotes only ...

The bodyparser in Express seems to be malfunctioning

When configuring my body parser, I implement the following code: const express = require('express') const app = express(); const bodyParser = require('body-parser'); app.use(bodyParser.json()); app.use(bodyParser.urlencoded({ extend ...

OnLoad event in ASP .NET not triggering

I'm currently dealing with a workaround that functions properly on my local system but fails to work after I deploy it to our server. The issue involves a webpage that launches an EXE file and then closes the webpage. Everything runs smoothly local ...

The Controller Method is passing NEW HTML, but the Ajax request is returning outdated HTML

In my work with .NET Framework / MVC 4 / C#, I encountered an issue where a View containing a Partial View was not being properly updated/refreshed after user actions such as clicking a SAVE or CANCEL button. The problem stemmed from an Ajax request callin ...

Having difficulty toggling checkboxes within a grid using the select all feature

In order to toggle checkboxes for a specific column within a grid, I encountered an issue within the JS "onUPCSelectAll" function with the eval statement displaying the following error message: JS runtime error: Object doesn't support property or meth ...

ReactJS encountered an error: _this3.onDismissID is not defined as a function

My goal is to retrieve the latest news related to a specific search term from a website, showcase them, and provide a dismiss button next to each news item for users to easily remove them if desired. Here's a snippet of the code I'm using: import ...

An array of deferred objects in a jQuery `$.when()` function

Currently, I am facing an issue with passing a variable amount of deferred functions to $.when. In order to accomplish this, the functions need to be packed in an array. Although I have attempted the solutions provided in this post and this one, the done a ...

Could a jquery slick carousel be used to modify the body background of a webpage?

Is it possible to have one of the divs in a carousel change the background of the page, while the carousel is active on that specific div? if ($('.carousel').slick('slickGoTo', 1)){ //if slick is on slide index 1 //change to another pag ...

Using JavaScript to dynamically populate form fields

I am currently working on developing a form that allows users to add additional fields themselves. They will have the ability to add up to 5 new "options", with each option containing up to 50 "variants". For example, an option could be "size" with varian ...

Chaining Promise Rejections in AngularJS

Creating chained promises is a task I need to tackle: var deferred = $q.defer(); $timeout(function() { deferred.reject({result: 'errror'}); }, 3000); deferred.promise.then(angular.noop, function errorHandler(result) { //additional action ...

Explore jQuery UI Tabs with remote content, highlighting the active tab with a link to the current page

Back in earlier versions of jQuery UI (<=1.8), when loading tabs, the link for a remote tab would be replaced with a local link. This allowed users to middle-click (or open in new browser tab) on the tab, and it would link back to the current page with ...

Creating an 8-bit grayscale JPEG image using HTML5 and encoding it from a canvas source

Is there a simple method to convert an 8-bit grayscale JPEG from Canvas using client side technologies in a web browser (such as HTML5, canvas, WebGL, and JavaScript)? Are there any pre-made JavaScript libraries available for use, without requiring extens ...

The radio button selection cannot be transmitted via email

Only the first radio button is selected <div class="field_radio" name="preference" > <input class="radio1" type="radio" name="preference" id="preference" value="team" onclick="ShowHideDiv()" /><label for="radio1"> ...

When the ng-model is updated within a promise's .then() function, the ng-change

I've encountered an issue with ng-change in a select not triggering when I update the ng-model parameter within my promise.then function. Here's my select code: <select ng-model="currentReport" ng-options="rpt.ReportDisp for rpt in availa ...

What sets apart the process of Installing Bootstrap with incorporating its suggested files into an HTML document?

As a novice in the world of web development, I find myself grappling with confusion. My current learning endeavor involves delving into Bootsrap through a project centered around developing a portfolio using both Bootstrap and Sass. However, an issue has a ...

methods to add an object to formData in vuejs

I am having trouble appending an object to FormData using Axios. I do not want to send data by JSON.stringify() data () { return { product: { title: '', description: '', properties: { ...