'Selecting div's href's and submitting form?

I have this code in my html:

<div id="div1">
<a href="a"> Apple </a>
<a href="b"> Orange </a>
<a href="c"> Lemon </a>
<a href="d"> Banana </a>
</div>

<form action=" ">
<input type="text" name="q" id="input1" >
</form>

When ever I click anything in the div1 is set to the input thanks to @alex

Is it possible to submit the form too though?

My JavaScript looks like this:

$('#div1 > a').click(function(event) {
   event.preventDefault();
   $('#input1').val($(this).attr('href'));
});

I have a fiddle of how it looks like. http://jsfiddle.net/FCHpn/



Solution 1:[1]

This will submit the form which #input1 sits in.

$('#div1 > a').click(function(event) {
   event.preventDefault();
   $('#input1').val($(this).attr('href')).closest('form').submit();
});

Solution 2:[2]

To submit the form you just have to call .submit() on the form element. I would give the form an id and then call something like

$("#formid").submit();

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 kapa
Solution 2 rahul