Single Form - Submitting value of a non clicked button when a separate input (submit type) is pressed?

StackOverflow https://stackoverflow.com/questions/23595264

  •  20-07-2023
  •  | 
  •  

Вопрос

How do I submit the value of a button that the user has not pressed in a single form when the user presses another input type=submit?

I have tried to trigger the click of the button (not pressed), but it is only causing the triggered button value to submit.

Is there any way to submit two buttons even when one is pressed?

For example, if "input" is pressed then also press button (id="button").

 $("input").click(function()
 {
        $("#button").trigger('click');
 });

EDIT: New function with submit ability but still not working as hoped.

$("input").click(function(e)
{
    e.preventDefault();
    e.stopPropagation();
    $("#button").trigger('click');
    $("#log_form").submit();
});
Это было полезно?

Решение

You have to stop the propagation of the event that the clicked button is triggering.

So, the right code is this:

$("input").click(function(e)
 {
        e.preventDefault();
        e.stopPropagation();     
        $("#button").trigger('click');
 });

Другие советы

HTML with JavaScript would be cool... Here I'll provide you simple code (^_^)

JavaScript: Insert in between head tags

<script language="javascript" type="text/javascript">
// <![CDATA[

    function button_onclick() {
        window.navigate("page2.html");
    }

// ]]>
</script>


In between body tags, Insert this code

<input id="button" type="button" value="Page2" style="width:150px; height:30px;" onclick="button_onclick()" />
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top