Hi,

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

Thanks

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

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

<head>
<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 );
  };
};
</script>
</head>
<body>
  <input id="name" type="text" name="name" />
  <a id="link" href="#">Click Me</a>
</body>

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

Member Avatar for langsor

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.