Code below sends values to the test1.php with button. Is there any way to use <a> link to do same thing?


<form method="post" name="form">
<input type="text" name="name" />
<input type="submit" name="submit1" value="submit1" onclick="javascript: form.action='test1.php';" />

If you know the values you want to send

Static values

<a href="test1.php?name=value">Click Me</a>

PHP populated values

<a href="test1.php?name=<? print $_GET['name'] ?>">Click Me</a>

Javascript populated values

<script type="text/javascript">
window.onload = function () {
  var input = document.getElementById('name');
  var link = document.getElementById('link');
  input.onchange = function () {
    link.setAttribute( 'href', 'test1.php?name=' + this.value );
  <input id="name" type="text" name="name" />
  <a id="link" href="#">Click Me</a>

Above javascript compacted some

window.onload = function () {
  document.getElementById('name').onchange = function () {
    document.getElementById('link').setAttribute( 'href', 'test1.php?name=' + this.value );

Otherwise, there is no way to send data via POST with an <a> link which is by its nature a GET method.

Hope this helps


If not POST then, it is not suitable for me. Anyway, thanks for your answer

You can send method POST data via a form or via Ajax
You can submit the form via an <a> link if you want to do that
And you can have hidden input values in a form ...

Good luck