<ul class="ul_dropdown">
<li><a href="#" name="option1">Option 1</a></li>
<li><a href="#" name="option2">Option 2</a></li>
</ul>
<input id="linkName" type="hidden" />
$('ul_dropdown li a').on('click', function() {
$('#linkName').val( $(this).attr('name') );
$(this).closest('form').submit();
});
submit form from dropdown menu text link
-
30-07-2022 - |
Question
I have dropdown menu with some actions, but I need help to submit form on click via text link and pass the name attribute to the POST method. I have jQuery already on the page and code below works but name
attribute is not sent.
<form id="myForm" name="myForm" action="" method="post">
<button class="dropdown">Actions</button>
<ul class="ul_dropdown">
<li><a href="#" name="option1" onclick="$(this).closest('form').submit()">Option 1</a></li>
<li><a href="#" name="option2" onclick="$(this).closest('form').submit()">Option 2</a></li>
</ul>
... other form fields ...
</form>
Solution 2
OTHER TIPS
This is not how HTML works, a link doesnt send any information other than the url you set in the href attribute, you could do this
<li><a href="?name=option2" name="option2" >Option 2</a></li>
which does not require a form, or if you wish to Post you will need each option to be a seperate form, or you could use the solution provided by isherwood.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow