I have this code in asp
and javascript
.
<%if trim(ind_tipo_proposta_pj) = "S" then%>
var onum_seq_proposta_pj_ts = eval(txt_chamada + txt_prefixo + '<%Response.Write prefixo%><%Response.Write nome_campo_cod_ts%>' + txt_sufixo);
<%else%>
var onum_seq_proposta_ts = eval(txt_chamada + txt_prefixo + '<%Response.Write prefixo%><%Response.Write nome_campo_cod_ts%>' + txt_sufixo);
<%end if%>
I need to make it cleaner, without the asp
tags. What happens is that I have a lot of doubt when the subject is asp
. Well, a few days ago colleague TobyMosque helped me a lot in doing something similar. I'm not here asking you to do it for me, otherwise I'll always be asking, but a tip or a line to follow. My attempt went into this:
if()
var onum_seq_proposta_pj_ts = "<%= trim(nome_campo_cod_ts) %>" || "";
var onum_seq_proposta_ts = "<%= trim(nome_campo_cod_ts) %>"
I could not finish the if
and I also do not know if ou
is correct. Note that there is a if
in asp
, if it is legal, it loads a variable, otherwise it carries another variable. I wonder if I kill if
of asp
and put if
of js
, if tilt. I could also do a ternary, but how to do this in a one-variable statement. I would do in if
, but in the statement I do not know if it is possible (I think not). How do I, or rather, which way to go?
Making my attempts here I got to this code, but I do not know if to be right, because to test I will have to change a lot more things, but just tell me. This is the way? I did not kill 100% of the asp
, but it gave an optimized percentage of asp
.
var onum_seq_proposta_pj_ts = null;
var onum_seq_proposta_ts = null;
<%if trim(ind_tipo_proposta_pj) = "S" then%>
onum_seq_proposta_pj_ts = "<%= trim(nome_campo_cod_ts) %>" || onum_seq_proposta_ts = "<%= trim(nome_campo_cod_ts) %>";
<%end if%>
Okay, actually the variables txt_prefixo
and txt_sufixo
are variable. They already know how to treat. See how they're declared:
var txt_prefixo = '';
var txt_sufixo = '';
try{
txt_prefixo = '.document.form01.';
txt_sufixo = '';
......
TobyMosque, is this how I should use the object?
var txt_prefixo = '';
var txt_sufixo = '';
window["objeto"] = null;
var nome_campo_cod_ts_id = "<%= trim(nome_campo_cod_ts) %>";
var onum_seq_proposta_pj_ts = null;
var onum_seq_proposta_ts = null;
var txt_chamada = "";
var onum_seq_proposta_pj_ts_id = "<%= trim(ind_tipo_proposta_pj)%>" == "S";
if(onum_seq_proposta_pj_ts_id)
window[txt_chamada][txt_prefixo][onum_seq_proposta_pj_ts][txt_sufixo];
else
window[txt_chamada][txt_prefixo][onum_seq_proposta_ts][txt_sufixo];
I'm actually having a hard time deleting this try..catch
, that is, replacing with a cleaner javascript code:
try {
txt_prefixo = '.document.form01.';
txt_sufixo = '';
<%if trim(ind_tipo_proposta_pj) = "S" then%>
var onum_seq_proposta_pj_ts = eval(txt_chamada + txt_prefixo + '<%Response.Write prefixo%><%Response.Write nome_campo_cod_ts%>' + txt_sufixo);
<%else%>
var onum_seq_proposta_ts = eval(txt_chamada + txt_prefixo + '<%Response.Write prefixo%><%Response.Write nome_campo_cod_ts%>' + txt_sufixo);
<%end if%>
} catch (e) {
txt_prefixo = '.document.all[\'';
txt_sufixo = '\']';
<%if ind_tipo_proposta_pj = "S" then%>
var onum_seq_proposta_pj_ts = eval(txt_chamada + txt_prefixo + '<%Response.Write prefixo%><%Response.Write nome_campo_cod_ts%>' + txt_sufixo);
<%else%>
var onum_seq_proposta_ts = eval(txt_chamada + txt_prefixo + '<%Response.Write prefixo%><%Response.Write nome_campo_cod_ts%>' + txt_sufixo);
<%end if%>
}
This try..catch
is within that if in ASP:
<%if trim(nome_campo_cod_ts)<> "" then%>
try {
txt_prefixo = '.document.form01.';
txt_sufixo = '';
<%if trim(ind_tipo_proposta_pj) = "S" then%>
var onum_seq_proposta_pj_ts = eval(txt_chamada + txt_prefixo + '<%Response.Write prefixo%><%Response.Write nome_campo_cod_ts%>' + txt_sufixo);
<%else%>
var onum_seq_proposta_ts = eval(txt_chamada + txt_prefixo + '<%Response.Write prefixo%><%Response.Write nome_campo_cod_ts%>' + txt_sufixo);
<%end if%>
} catch (e) {
txt_prefixo = '.document.all[\'';
txt_sufixo = '\']';
<%if ind_tipo_proposta_pj = "S" then%>
var onum_seq_proposta_pj_ts = eval(txt_chamada + txt_prefixo + '<%Response.Write prefixo%><%Response.Write nome_campo_cod_ts%>' + txt_sufixo);
<%else%>
var onum_seq_proposta_ts = eval(txt_chamada + txt_prefixo + '<%Response.Write prefixo%><%Response.Write nome_campo_cod_ts%>' + txt_sufixo);
<%end if%>
}
<% else %>
try {
txt_prefixo = '.document.form01.';
txt_sufixo = '';
<%if ind_tipo_proposta_pj = "S" then%>
var onum_seq_proposta_pj_ts = eval(txt_chamada + txt_prefixo + '<%Response.Write prefixo%>num_seq_proposta_pj_ts' + txt_sufixo);
<%else%>
var onum_seq_proposta_ts = eval(txt_chamada + txt_prefixo + '<%Response.Write prefixo%>num_seq_proposta_ts' + txt_sufixo);
<%end if%>
} catch (e) {
txt_prefixo = '.document.all[\'';
txt_sufixo = '\']';
<%if ind_tipo_proposta_pj = "S" then%>
var onum_seq_proposta_pj_ts = eval(txt_chamada + txt_prefixo + '<%Response.Write prefixo%>num_seq_proposta_pj_ts' + txt_sufixo);
<%else%>
var onum_seq_proposta_ts = eval(txt_chamada + txt_prefixo + '<%Response.Write prefixo%>num_seq_proposta_ts' + txt_sufixo);
<%end if%>
}
<%end if%>