简体   繁体   中英

using js functions within js functions in html.erb

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM