简体   繁体   English

使用PHP的href链接将输入文本框值传递到另一个页面

[英]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. 我有一个具有值的输入标签文本框,我希望使用href标签将该值从一个页面传递到另一页面。 Is this possible? 这可能吗?

Here's my HTML code 这是我的HTML代码

<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 这是我的代码,使用php将其传递到另一个页面

but when I echo the value in page 2 it returns blank even though I put 1234 in the text field 但是,当我回显第2页中的值时,即使我在文本字段中输入1234,它也会返回空白

<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. 在此先感谢您提供的所有帮助。

最简单的js解决方案:

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

Your HTML looks a bit messy with inline event handlers which is not good. 您的HTML使用内联事件处理程序看起来有点混乱,这不好。 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 演示@ 小提琴

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM