Pass Input Tag Value to as Href Parameter

Pass input tag value to as href parameter

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>

How to pass input value to href

use get method

<form action="index.php" method="GET">
<input type="search" name="search" />
<input type="submit" name="submit" />
</form>

OR

<form action="index.php" method="GET">
<input type="search" name="search" />
</form>

and in php you grab the value by $_GET['search']

how to pass two text box value to a href link

It is a good practice to write your script in a function & call it on HTML tags.
So, here's your working demonstration with your scenario -

function changeUrl() {  let lattitude = document.getElementById('lat3').value;  let longitude = document.getElementById('lon3').value;  let target = document.getElementById('myAnchor');  let seperator = encodeURI(",");  let href = 'https://www.google.com/maps/dir/?api=1&origin=' + lattitude + seperator + longitude + '&destination=2.183180,102.261803';  target.href = href;  console.log(target.href);}
<a target="_blank" href="" onclick="changeUrl()" id="myAnchor">map</a>                      <input type="text" value="1234.5678" id="lon3"><input type="text" value="0567.1211" id="lat3">

PHP Passing Input values through href to another page

Your variable not parse inside single quotes. your <? echo '$data['id']' ?> should be <?php echo $data['id'] ?>

 <input type="text" name="a" id="a" />
<a href="xxx.php?id = <?php echo $data['id'] ?>&mk=">CLICK</a>"
<a id="link" href="xxx.php?id=111&mk=">CLICK</a>

Edit:-
simply add one more hidden fields to store id value as well and get value in js and assign to href

 <input type="text" name="idval" id="idval" value="100" />
<input type="hidden" name="mk" id="mkval" value="101" />

Js:-

var idval = $('#idval').val();
var mk = $('#mkval').val();
var link = 'xxx.php?id=' + idval + '&mk=' + mk;

$("#link").attr("href", link);

Working Demo



Related Topics



Leave a reply



Submit