Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pass input tag value to as href parameter

I want to pass the value of input tag as parameter(quantita) in href. Should i use javascript to do this?Sorry for my english Thanks

<input type="text" id="qta_field" value="${item.value}"/><a href="updateItem?codice=${item.key.codice}&quantita=">update</a>

enter image description here

like image 686
Alex Avatar asked Nov 26 '14 12:11

Alex


People also ask

How do you pass a value into an href?

You need add quotes for your href , besides, you also need to use urlencode to encode the variable. . '">$compname</a>" ?? The last " should be a ' instead.

Can we pass variable in href?

href”, append the variable to it (Here we have used a variable named “XYZ”). Then we need to append the value to the URL. Now our URL is ready with the variable and its value appended to it. In the example below, we will append a variable named 'XYZ' and its value is 55.

How do you make a dynamic HREF in HTML?

getElementById('someDiv'); // create <a> tag var tag = document. createElement(a); // set the href attribute tag. setAttribute('href', exampleHref); // append the node to the parent div. appendChild(tag);

Can we pass value in anchor tag?

The HTML Anchor Link will be assigned an OnClick event handler and when clicked, the value of the TextBox will be set in the HREF attribute of the HTML Anchor Link using JavaScript. When the HTML Anchor Link is clicked, the TextBox value will be passed to the other Page as QueryString parameter.


2 Answers

The easiest way to do it with link and without any library:

<input type="text" id="qta_field" value="${item.value}"/>
<a href='' onclick="this.href='updateItem?codice=${item.key.codice}&quantita='+document.getElementById('qta_field').value">update</a>
like image 168
Simcha Avatar answered Sep 22 '22 22:09

Simcha


To send data from an input to the server, you should use a form.

<form action="updateItem">

  <input id="qta_field" name="quantita" value="${item.value}">
  <input type="hidden" name="codice" value="${item.key.codice}">

  <button>update</button>

</form>
like image 36
Quentin Avatar answered Sep 25 '22 22:09

Quentin