Drogebot Drogebot - 1 month ago 6
HTML Question

Make a html attributie with button role submit a form

I need to have my html attribute submit a form. My problem is that a normal button attribute is able to use the type="submit" and other attributes using role="button" don't do anything with the type.

So how do I make it submit a form? If you can give me a script to do it, that would be fine too.

(I don't know javascript myself)

My current code:

<form action="myloc" method="post">
<div class="input-group col-lg-6">
<a type="submit" class="btn btn-default input-group-addon" role="button">
Search<span class="glyphicon glyphicon-search" aria-hidden="true"></span>
</a>
<input type="search" class="form-control" name="search" id="search" placeholder="Search">
</div>
</form>

Answer

If I understand you correctly you want to submit the form when you press the button using javascript?

<form id="test" action="myloc" method="post">
   <div class="input-group col-lg-6">
      <a type="submit" class="btn btn-default input-group-addon" role="button" onclick="document.getElementById('test').submit();>
        Search<span class="glyphicon glyphicon-search" aria-hidden="true"></span>
      </a>
      <input type="search" class="form-control" name="search" id="search" placeholder="Search">
   </div>
</form>

Notice that what I did was to set an id ("test") on the form and then added an onclick event to the anchor element.

Comments