javascript数组不正常

I am facing some problems arrays in php,,

<input  class="form-control" placeholder="Start Time"
value="'.date("H.i").'" type="text" name="starttime[]" id="starttime"/>
</div>
<div class="col-lg-4">
<input  class="form-control" name="endtime[]" id="endtime" onchange="myfunction1()" value="00.00" type="text" placeholder="End Time">

This is my ajax code and when I change end time It must be show other text box

<input class="form-control" name="kmcost" id="exkms" type="text" placeholder="Cost">

But single entry working but second entry(array) Not woeking my javascript code is here please help me..

my javascript is here..

function myfunction1()
{
    var ftime = document.getElementById("starttime").value;
    var etime = document.getElementById("endtime").value;

    var timeanswer = etime - ftime;

    var localtottme = document.getElementById("textbox3").value;
    if(timeanswer > 8)
    {
        var totextme = timeanswer-8;
    }
   var exkms = document.getElementById('exkms');
exkms.value=totextme;
}

Try this:

function myfunction1()
{
    // fetch value of element as string, x2
    var ftime = document.getElementById("starttime").value;
    var etime = document.getElementById("endtime").value;

    // fetch hour as string, then convert to integer, x2
    ftime = parseInt(ftime.split(':')[0]);
    etime = parseInt(etime.split(':')[0]);

    // calculate hour difference, initialize remainder variable to 0
    var hourDifference = etime - ftime;
    var eightHourRemainder = 0;

    // check if hour difference is more than 8, if so then calculate remainder variable
    var localtottme = document.getElementById("textbox3").value;
    if(hourDifference > 8)
    {
        eightHourRemainder = hourDifference - 8;
    }

    // set element value to remainder variable
    var exkms = document.getElementById('exkms');
    exkms.value=eightHourRemainder;
}