Alex
Alex

Reputation: 2125

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

Upvotes: 6

Views: 61468

Answers (4)

Simcha
Simcha

Reputation: 3400

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>

Upvotes: 20

andrew
andrew

Reputation: 9593

You can use the document.queryselector to locate and manipulate the href attribute with js

Example:

input = document.querySelector('input');
a = document.querySelector('a');
a.setAttribute('href',a.getAttribute('href')+input.value);
<input type="text" id="qta_field" value="test"/>
<a href="updateItem?codice=${item.key.codice}&quantita=">update</a>

Upvotes: 1

Quentin
Quentin

Reputation: 944556

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>

Upvotes: 4

Buisson
Buisson

Reputation: 539

set an id or a class to your <a> for example : <a id='myA'>

So you can use jQuery like this :

jQuery(document).ready(function(){
    jQuery('qta_field').change(function(){
        var tmpVal = jQuery('#qta_field').val();
        var tmphref = jQuery('#myA').attr('href');
        tmphref = tmphref+tmpVal;
        jQuery('#myA').attr('href',tmphref);
    });
});

Upvotes: 2

Related Questions