1

ok should be an easy one for everyone,... i am calling a javascript function in the tag of a button using inclick. Im trying to get that function to have three different parameters. The function then submits three different times, which should end up being three different records in a ruby table. But i cant see why this doesnt work...

<script>
function submiteffort( elem )
{
    // Elem 1
    $("#effort_hours").val( $( elem ).val() );
    $("#task_id").val( elem.id );
    $("#effort_form").submit();
    return true;  
}

function medium( leave, toil, sick)
{
    var dave = submiteffort(document.getElementsByName(leave));

    if(dave == true){
        var dave2 = submiteffort(document.getElementsByName(toil));
    }

    if(dave2 == true){
        submiteffort(document.getElementsByName(sick));
    }
}
</script>

<div class="startleft">
    <table>
        <tr>
            <td>Leave</td>
            <td><input class="dayinput" type="text" name="Leave" placeholder="0" ></td>
        </t>
        <tr>
            <td>TOIL</td>
            <td><input class="dayinput" type="text" name="TOIL" placeholder="0"></td>
        </tr>
        <tr>
            <td>Sick</td>
            <td><input class="dayinput" type="text" name="Sick" placeholder="0"></td>
        </tr>
        <tr>
            <td>Total</td>
            <td><input id="total" class="total_low" type="text" value="0" disabled="" name="Dave">
        </tr>
        <tr>
            <td></td>
        <td><button onclick="medium('Leave','TOIL','Sick')">Commit</button></td>
        </tr>
    </table>
    </div>

For some reason this only submits 1 record into the table and i cant figure out why.

1 Answer 1

1

Well if you submit the form, the page refreshes, and the other 2 function calls don't execute. You'd have to use AJAX to send data to the backend in 3 separate function calls.

Sign up to request clarification or add additional context in comments.

1 Comment

how would you do that may i ask?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.