4
Reading some comments and especially the comments of Mr Tobymosque, I try today to avoid the use of Eval(). Well, now comes the following. In simple expressions, how do I replace it? See below a variable statement that I took here in the system that I work on and see if my approach is correct? Due to a problem we had here today, I’m not being able to test and in jsfiddle I can’t, because the page has a lot called Asp and is extremely large, because there is dependency on other pages.
function prorrogaVencimento(pLinha) {
var intI = pLinha;
var v_num_seq_cobranca = eval('form01.num_seq_cobranca_' + intI + '.value');
var v_nom_tipo_ciclo = eval('form01.nom_tipo_ciclo_' + intI + '.value');
var v_txt_num_linha_digitavel = eval('form01.num_linha_digitavel_' + intI + '.value');
var v_num_seq_fatura_ts = eval('form01.num_seq_fatura_ts_' + intI + '.value');
var v_ind_tipo_cobranca = eval('form01.ind_tipo_cobranca_' + intI + '.value');
var v_mes_ano_ref = eval('form01.mes_ano_ref_' + intI + '.value');
var v_ind_situacao = eval('form01.ind_situacao_' + intI + '.value');
if ((v_ind_tipo_cobranca == '5' || v_ind_tipo_cobranca == '6') & v_ind_situacao == 'Vencidas' {
alert('Ação não permitida para o tipo da cobrança.');
return;
}
I did so, but I think it’s bad:
var v_num_seq_cobranca = eval('form01.num_seq_cobranca_' + intI + '.value');
for that reason:
var v_num_seq_cobranca = form01.num_seq_cobranca_[intI].value;
There’s that other approach too:
var v_num_seq_cobranca = window['form01.num_seq_cobranca_' + intI].value;
Thanks, I opted for your first opening which is the same as the bfavaretto.
– pnet
In reality this approach is the "only" correct (in the sense of "minimal"). The rest of the answer is just exemplifying the concepts, and showing what would be the result of your other attempts.
– mgibsonbr