0

CODEIGNITER

I want to submit two forms with one button. if a radio button is not checked i only submit the first form, but when i check the radio button appear more information (second form). I want to submit the 2 forms when the radio button is selected.

The problem is that it´s only submiting form 1 even when the radio button is checked.

<script>
submitForms = function(){
if(document.getElementById('tipo').checked) {
    document.getElementById("form2").submit();
    document.getElementById("form1").submit();
}else{
    document.getElementById("form1").submit();

}
}
</script>
Sara
  • 1

1 Answers1

0

This is a native JavaScript solution:

    <script>
    document.addEventListener("DOMContentLoaded", function (event) {
        document.getElementById("myButton").addEventListener("click", function () {
            console.log(document.getElementById("form1").value);
            if (document.getElementById("tipo").checked) {
                console.log(document.getElementById("form2").value);
            }
        });
    });
    </script>

You might also take a look at javascript Submit multiple forms with one button

John
  • 130
  • 1
  • 8