admin管理员组文章数量:1432196
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.
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.
Share Improve this question asked Mar 2, 2015 at 9:18 Roi patrick FlorentinoRoi patrick Florentino 1771 gold badge3 silver badges17 bronze badges 3- You need to submit form to get value in another page. – Mihir Bhatt Commented Mar 2, 2015 at 9:19
-
… or use JavaScript to read the value, and put it into the URL that the link refers to via its
href
attribute, f.e. as a query string parameter. – C3roe Commented Mar 2, 2015 at 9:52 - Javascript (or jQuery) is your friend here. Have you tried anything so far in terms of the JS/jQuery? – lshettyl Commented Mar 2, 2015 at 10:06
2 Answers
Reset to default 2The simplest js solution:
<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. It's highly remended 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
本文标签: javascriptpass a input textbox value to another page using href link using phpStack Overflow
版权声明:本文标题:javascript - pass a input textbox value to another page using href link using php - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745563558a2663621.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论