2
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 tags asp
. The thing is, I have a lot of doubt when it comes to asp
. Well, a few days ago, my colleague Tobymosque helped me a lot in doing something similar. I am not here asking you to do it for me, otherwise I will always be asking, but a hint or a line to be followed. My attempt was in this:
if()
var onum_seq_proposta_pj_ts = "<%= trim(nome_campo_cod_ts) %>" || "";
var onum_seq_proposta_ts = "<%= trim(nome_campo_cod_ts) %>"
I couldn’t finish the if
and I also don’t know if the ou
is correct. See that there is a if
in the asp
, if legal, loads a variable or loads another variable. I wonder if I kill the if
of asp
and put a if
of js
, if it will give tilt. I could also make a ternary, but how to do it in a statement of a variable. I would if
, but in the statement I don’t know if it’s possible(I don’t think so). As I do, or rather, which way to go?
Making my attempts here I arrived at this code, but I do not know if it is right, because to test I will have to change much more things, but just tell me. Is this the way? I didn’t kill 100% the asp
, but gave an optimized in relation to the 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 variables. They already know how to treat. See how they are declared:
var txt_prefixo = '';
var txt_sufixo = '';
try{
txt_prefixo = '.document.form01.';
txt_sufixo = '';
......
Tobymosque, this is how I should use 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];
In fact I’m having great difficulty eliminating this try..catch
, i.e., replace with 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%>
}
That one try..catch
is inside 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%>
I didn’t think about it. It can be a good exit yes, it is much more readable. It can be a path or a line to be followed. If it is a PF proposal, this field should come with "N". If I put value on the page as "S", as it would be if it is a PF proposal?
– pnet
In fact if you look further up the right is to put the
value
with the printing of the contents of the variable that is in theASP
. This proposal type variable is in theASP
(you read from the database or a text file, for example, usingASP
), or is in a fieldHTML
and this page receives this variable ?– Maicon Herverton
It comes from the bank. The problem is that the site is very large, this is just a module for which we were hired to provide maintenance. The site is very old. That question I have. If you set value to "S" and enter "N", it changes value, right?
– pnet
I think you’re missing @pnet. I just fixed the field in the example code, so you can test it. But in your there, on your page, you will print the value of the result of the variable that came from the database, I will call it
TIPO_DE_PROPOSTA
and do the following:<input type="hidden" name="ind_tipo_proposta_pj" id="ind_tipo_proposta_pj" value="<%= trim(**TIPO_DE_PROPOSTA**) %>"/>
– Maicon Herverton
Okay, I get it now. In this case he himself comes from the BD(ind_tipo_proposta_pj)
– pnet
OK I edited the code because I understood what its original code proposed. It besides checking the value of the variable
ind_tipo_proposta_pj
is legal entity "S", the codeJavaScript
of the conditionsif
andelse
executes the cluster of other variables, some of the bank (understanding that what comes from yourASP
came from the bank) and are theynome_campo_cod_ts
andprefixo
, and others of theJavaScript
and it’s themtxt_chamada
,txt_prefixo
andtxt_sufixo
.– Maicon Herverton
Let’s go continue this discussion in chat.
– Maicon Herverton