Get input date value

-1

I have two input date created, and I would like to get the date of the two by a button.

            <div class='col-md-5 col-lg-4'>
            <div class="form-group">
                <span>Inicio</span>
                        <div class='input-group date' id='datetimepicker6'><span></span>
                                <input type='text' class="form-control" />
                                <span class="input-group-addon">
                                        <span class="glyphicon glyphicon-calendar"></span>
                                </span>
                        </div>
                </div>
    </div>
    <!-- -->
    <div class='col-md-5 col-lg-4'>
        <div class="form-group">
                <span>Fim</span>
            <div class='input-group date' id='datetimepicker7'>
                <input type='text' class="form-control" />
                <span class="input-group-addon">
                    <span class="glyphicon glyphicon-calendar"></span>
                </span>
            </div>
        </div>
    </div>
    <!-- -->
    <div class="col-md-5 col-lg-3">
        <div id="espaco"></div>
            <button type="button" class="btn btn-primary" data-toggle="button" aria-pressed="false" autocomplete="off" onclick = "botaoFunfa>
              Buscar
            </button>
    </div>

Every time I try to get it it shows the code and not the value

JS

function botaoFunfa() {
    var teste = document.querySelector("#datetimepicker6");
    console.log(teste);
}

I was able to get the value as follows:

I was able to resolve it as follows:

function botaoFunfa() {
    var teste = document.querySelector(".switch");
    var StringData = teste.textContent || teste.innerText; 
    console.log(StringData);
}

So he would show the day, month and year. Note: the switch class is bootstrap itself.

But for some reason it's giving a bug, and it does not take the two input dates, just one.

    
asked by anonymous 08.02.2018 / 17:41

1 answer

1

Here's a solution below, just look for the val() of each button to be clicked.

    
    $('#btn').click(function(){
      var inicio = $('#inicio').val(),
      fim = $('#fim').val();       
       console.log('data inicial: ' + inicio + ' data final: ' +fim);
       
    })
    
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">

 <div class='col-md-5 col-lg-4'>
            <div class="form-group">
                <span>Inicio</span>
                        <div class='input-group date' ><span></span>
                                <input id='inicio' type='text' class="form-control" />
                                <span class="input-group-addon">
                                        <span class="glyphicon glyphicon-calendar"></span>
                                </span>
                        </div>
                </div>
    </div>
    <!-- -->
    <div class='col-md-5 col-lg-4'>
        <div class="form-group">
                <span>Fim</span>
            <div class='input-group date' >
                <input id='fim' type='text' class="form-control" />
                <span class="input-group-addon">
                    <span class="glyphicon glyphicon-calendar"></span>
                </span>
            </div>
        </div>
    </div>
    <!-- -->
    <div class="col-md-5 col-lg-3">
        <div id="espaco"></div>
            <button type="button" id="btn" class="btn btn-primary" data-toggle="button" aria-pressed="false" autocomplete="off" >
              Buscar
            </button>
    </div>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><scriptsrc="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
    
    
08.02.2018 / 17:53