Submitting form with the radio button and not by submit button - html

I have a form with many radio button in html and I want to submit the form using only radio button and not by submit button. Is it possible?

This answer uses jQuery
$('.radiobtnclass').on('click', function() {
$('#formid').submit();
});
radiobtnclass is the class of the radio buttons you want to monitor
formid is the id of the form you wish to submit

You can add an onClick event to each radio tag like so:
<input type='radio' name='x' value='y' onClick='this.form.submit()'/>

<form name="yourForm" action="action.php" method="POST">
<input type="radio" name="radio" value="Radio button" onclick="document.forms['yourForm'].submit()" />
</form>

Related

How do I make it so that when I check one radio button, the other radio button in the same form get unchecked in React?

In the form below, when I click the first radio button then I click the second radio button, both remain checked. The behaviour I want is for when I click on radio button, the other radio button gets unchecked automatically. I am using React.js with styled components.
<form>
<input type="radio"/>
<input type="radio"/>
</form>
Give the same name to all the radio buttons (but different values).
<form>
<input type="radio" name="radio" value="1"/> 1st
<input type="radio" name="radio" value="2"/> 2nd
</form>
You have give each radio button a name property with the same value like "group1". Like so:
<form>
<input type="radio" name="group1"/>
<input type="radio" name="group1"/>
</form>

Href link on input button submit

How can i bind this link
<a href="edit?id=<c:out value='${person.id}' />">
to input button "submit" ?
try something like that. Hope this will fix your problem
href="\edit?id={{person.id}}"
Typically if you are using a submit button, then you will be inside a form. An example of this would be:
<form action="edit?id=<c:out value='${person.id}' />" method="post">
<!-- form fields here -->
<input type="submit" value="Submit" />
</form>
In this case, the submit button is "tied" to the form, and will post the form data to the link in the action value.
I found solution :
<input type="hidden" name="from" value="${param.from}">
Servlet.class
response.sendRedirect(request.getParameter("from"));

Hitting enter (return) key on a form with multiple submit buttons

If there are multiple submit buttons on a form,which submit button is triggered when user hits enter key in a input type="text"
HTML Standard (inplicit submission):
A form element's default button is the first submit button in tree
order whose form owner is that form element.
https://html.spec.whatwg.org/multipage/forms.html#implicit-submission
Give it a try:
<form>
<input type='text'>
<input onclick="alert('FIRST')" type="submit" value="FIRST" />
<input onclick="alert('SECOND')" type="submit" value="SECOND" />
</form>
It should be first type="submit" input.
Fiddle: http://jsfiddle.net/ddan/5tmwjdad/

How to set radio button value the same as another radio button onclick automatically

I have two radio buttons on form for user to click just one of them ..
How can I set the another radio button value onclick action of the 1st radio action ?
<input type="radio" id="Male" onclick= " ">
<input type="radio" id="AltMale" >

is it possible to combine radiobutton and submit in 1 submit button?

I have a radiobutton and the value gets submitted with a submitbutton. I only want a submitbutton that submits the value when clicked. So instead of a radiobutton and a submitbutton separate I want a radiobutton and submit button rolled into 1.
This is my code:
{foreach item=item key=key from=$memberships}
<input type="radio" type="hidden" name="membership" value="{$key}" checked="checked"/>
{$item}
{/foreach}
<input class="button" type="submit" value="{lang mkey='continue'} -->"/>
What I am trying to achieve is something like this:
replace the radiobutton and submit button with just a submit button.
<button type="submit" name="membership" value="{$key}">{$item}</button>
Would it be possible and how to do it?
You can have
<input type="radio" type="hidden" name="membership" value="{$key}" checked="checked" onclick="this.form.submit();"/>
or
<input type="hidden" type="hidden" name="membership" id="membership" value="{$key}">
<button type="submit" name="membership" onclick="document.formname.membership.value={$key}; return true;">{lang mkey='continue'}</button>
You could create a small image that looks like a radio button and map that as your submit button. This would give the illusion of having a radio button but when a user clicks it your form would submit.
If you really want to jazz it up, have a second image like a selected radio button and show that with something like an onClick() event.
Just don't have a submit button, and then use an onclick event for the radio button that submits the form.