Roi patrick Florentino
Roi patrick Florentino

Reputation: 177

pass a input textbox value to another page using href link using php

I have an input tag textbox which has a value and I want that value to be passed from one page to another using a href tag. Is this possible?

Here's my HTML code

<input type="text" placeholder="Place given Access Key" id="accesskeynum" name="accesskeynum" value="accesskeynum">

and here's my code to pass it to another page using php

but when I echo the value in page 2 it returns blank even though I put 1234 in the text field

<a href="immobilization_actions.php?action=immobilizerx&id=<?php echo $_POST['accesskeynum'] ?>" style="margin-right:50px;"><img src='style/Immobilize.png' height="75" width="75" onmouseover="this.src='style/Immobilize.png';" onmouseout="this.src='style/Immobilize.png';" /></a>

Please help me. Thanks in advance for all the help.

Upvotes: 1

Views: 10377

Answers (2)

D-Bennett
D-Bennett

Reputation: 155

The simplest js solution:

<a href="/immobilization_actions.php?action=immobilizerx" onclick="window.location=this.href+'?id='+document.getElementById('accesskeynum').value;return false;">Click</a>     

Upvotes: 2

lshettyl
lshettyl

Reputation: 8171

Your HTML looks a bit messy with inline event handlers which is not good. It's highly recommended to separate behavior from markup (presentation). So, let's try:

<input type="text" placeholder="Place given Access Key" id="accesskeynum" name="accesskeynum" value="accesskeynum">    

<a href="immobilization_actions.php?action=immobilizerx" style="margin-right:50px;"><img src='style/Immobilize.png' height="75" width="75" /></a>

And

var ele = document.querySelector("a");
var input =  document.querySelector("#accesskeynum");
ele.href += "&id="+ input.value;

input.addEventListener("change", function() {
    ele.href = ele.href.replace(/&id=[^"']*/, "");
    ele.href += "&id="+ this.value;
});

ele.addEventListener("mouseenter", function() {
    this.src='style/Immobilize.png';
});
ele.addEventListener("mouseleave", function() {
    this.src='style/Immobilize.png';
});

Demo@Fiddle

Upvotes: 0

Related Questions