Passing data to another page

-1

I need your help,

I have two forms, Form 1 Form 2

no Formulario 1 I have a date field, filling this date field I want it to copy to Formulario 2 without typing, can it do this using JAVASCRIPT ?

I can pull data from the other form through this line of code

Service
    var dia1Service = new Basics.Services.Services.Formulario.Dia1Service();

Form
   var dia1 = dia1Service.getByCadastroId(id);

Here is my validation with JAVASCRIPT:

function validaDataDois(campo, valor) {
        var variavelBasais = @(dadosBasais.isubrar);
        var variavelDia1 = @(dia1.isubrd1);

        var date = new Date(valor.split('/').reverse().join('/'));

        var dataAlta = $('[name="dtirr"]').val();
        var dataAltaValida = new Date(dataAlta.split('/').reverse().join('/'));


        var dateDia1 = '@(dia1 != null && !string.IsNullOrEmpty(dia1.dtd1) ? Convert.ToDateTime(dia1.dtd1).ToString("dd/MM/yyyy") : string.Empty)'
        var dateDia1Valid = new Date(dateDia1.split('/').reverse().join('/'));

        var dataRandomizado = '@Convert.ToDateTime(ViewBag.datarandomizacao.ToString()).ToString("dd/MM/yyyy")';
        var dataRando = new Date(dataRandomizado.split('/').reverse().join('/'));

        if (!isValidDate(valor)) {
            $('#dtirr-msg').show();
            $('#dtirr-msg').text('Data inválida: ' + dataAlta);
            $('[name="dtirr"]').val('');
        }else if(variavelBasais == "1"){
            if(dataAltaValida < dataRando){
                $('#dtirr-msg').show();
                $('#dtirr-msg').text('A data informada está menor que a data de randomização: ' + dataRandomizado);
                $('[name="dtirr"]').val('');
            }
        }else if(variavelDia1 == "1"){
// A DATA TEM QUE APARECER NESSE CAMPO ABAIXO
            $('[name="dtirr"]').val();
        }
        else {
            $('#dtirr-msg').hide();
            $('.valida_btn').prop('disabled', false).attr('disabled');
        }
    }
    
asked by anonymous 28.03.2017 / 15:32

1 answer

1

An alternative using just JavaScript is to save the value in the localStorage / sessionStorage and when you open the other page search for this value.

On the first form - assuming the transition will occur after a click of a button - save value to localStorage .

$('button').on('click', function() {
    localStorage.setItem('algumaDataEspecial', valorDaDataEspecial);
});

In the second form you look for this value in the localStorage and if it exists, put the value in the input

$(document).ready(function(){
    if(localStorage.getItem('algumaDataEspecial')){            
        var data = localStorage.getItem('algumaDataEspecial');
        //Colocar o valor no input, ou seja lá o que quer fazer
        localStorage.removeItem('algumaDataEspecial');
    }
});
    
28.03.2017 / 15:50