<a href> instead of the <input submit> button

I originally had a submit button.

<input class="submit" type="submit" class="input" value="Add" name="command" />

but now I would like to use <a href>. The problem is that it is value="Add"very important.

I am currently doing <a href>as follows.

<a href="javascript:document.register.submit();">submit</a>

Any suggestions? The problem is that the site does not pick up that this particular one <a href>was clicked and therefore will not run my php code.

+3
source share
3 answers

First of all, I highly recommend jquery. This makes a world of difference when working with javascript and simplifies a number of problems, especially in different browsers.

I suggest creating hidden input to set the value with.

<script type="text/javascript">
function submitFormWithValue(val){
  document.getElementById('command').value = val;
  document.forms["test"].submit();
}
</script>

<form id="test" name="test" action="#" method="post">
<input type="hidden" name="command" value="" />
</form>

<a href="javascript:submitFormWithValue('foo')">Submit</a>

, , , . jquery, javascript!

+4

: . JavaScript!

CSS, :

input.submit {
  margin: 0;
  padding: 0;
  border: none;
  color: blue;
  background-color: transparent;
  text-decoration: underline;
}
+10

Add hidden field and extra line in javascript:

<input type="hidden" name="command" />
<a href="javascript: document.register.command.value='Add'; document.register.submit();">
    Submit
</a>

However, you might be better off using CSS to style the submit button to see how you want it.

+4
source

Source: https://habr.com/ru/post/1745813/


All Articles