Inquiridor
Migração JAVASCRIPT -> JQUERY

Pergunta
-
Galera,
Procurei aqui no forum e encontreri alguns artigos sobre esta migração, mas vi que esta migração tem q ser feita na mao e na raça.
Tenho uma função bem grande, em javascript, que é acionada no evento onchange dos radio button.
Quis incrementar a minha pagina, e troquei os radios padroes, por uns radios com Jquery, e ai.. minhas funcões do on change pararam de funcionar, so funciona o Jquery.
Gostaria de se possivel, alguem me ajude a fazer esta migração. É uma pagina em CLASSIC ASP, e, basicamente é um carrinho de comprar, onde o cliente pode montar o seu pacote.
Obs.: O codigo é meio redundante, um para cada tipo de radio. Tem como criar uma função Jquery e chamar ela? Ao inves de copiar e colocar todo o codigo dentro da tag
$('radio1').change({função});
$('radio2').change({função});
$('radio2').change({função});
Segue o codigo do JAVASCRIPT da minha pagina.function AtualizaValorTotal(){
var v_total = 0.0;
var v_total_item = 0.0;
var v_total_hosp = 0.0;
var v_total_conv = 0.0;
var v_total_onib = 0.0;
/*Atualizando Item*/
if (document.frm_item.itens!=undefined){
if (document.frm_item.itens.length==undefined){
var v_unitario = document.getElementById('vlr_item_' + document.frm_item.itens.value);
var v_quantidade = document.getElementById('qtd_item_' + document.frm_item.itens.value);
if ( v_quantidade.value > 0){
v_total_item += v_unitario.value * v_quantidade.value;
document.frm_item.itens.checked = true;
}
else
{
document.frm_item.itens.checked = false;
}
}
else{
for (i = 0; i < document.frm_item.itens.length; i++){
var v_unitario = document.getElementById('vlr_item_' + document.frm_item.itens[i].value);
var v_quantidade = document.getElementById('qtd_item_' + document.frm_item.itens[i].value);
if ( v_quantidade.value > 0){
v_total_item += v_unitario.value * v_quantidade.value;
document.frm_item.itens[i].checked = true;
}
else
{
document.frm_item.itens[i].checked = false;
}
}
}
v_total += v_total_item
v_total_item = (v_total_item.toString()).replace(".", ",")
if(v_total_item.indexOf(',') < 0) { v_total_item += ',00'; }
document.getElementById('vlr_item').innerHTML = "Total em itens: <b>R$ " + v_total_item + "</b>";
}
/*Atualizando Hospedagem*/
if (document.frm_item.hospedagem!=undefined){
if (document.frm_item.hospedagem.length==undefined){
var v_unitario = document.getElementById('vlr_hosp_' + document.frm_item.hospedagem.value);
if ( document.frm_item.hospedagem.checked == true){
v_total_hosp += v_unitario.value * 1;
}
}
else{
for (i = 0; i < document.frm_item.hospedagem.length; i++){
var v_unitario = document.getElementById('vlr_hosp_' + document.frm_item.hospedagem[i].value);
if ( document.frm_item.hospedagem[i].checked == true){
v_total_hosp += v_unitario.value * 1;
}
}
}
v_total += v_total_hosp
v_total_hosp = (v_total_hosp.toString()).replace(".", ",")
if(v_total_hosp.indexOf(',') < 0) { v_total_hosp += ',00'; }
document.getElementById('vlr_hospedagem').innerHTML = "Total em hospedagem: <b>R$ " + v_total_hosp + "</b>";
}
/*Atualizando Onibus*/
if (document.frm_item.onibus!=undefined){
if (document.frm_item.onibus.length==undefined){
var v_unitario = document.getElementById('vlr_onib_' + document.frm_item.onibus.value);
if ( document.frm_item.onibus.checked == true){
v_total_onib += v_unitario.value * 1;
}
}
else{
for (i = 0; i < document.frm_item.onibus.length; i++){
var v_unitario = document.getElementById('vlr_onib_' + document.frm_item.onibus[i].value);
if ( document.frm_item.onibus[i].checked == true){
v_total_onib += v_unitario.value * 1;
}
}
}
v_total += v_total_onib
v_total_onib = (v_total_onib.toString()).replace(".", ",")
if(v_total_onib.indexOf(',') < 0) { v_total_onib += ',00'; }
document.getElementById('vlr_onibus').innerHTML = "Total em onibus: <b>R$ " + v_total_onib + "</b>";
}
/*Atualizando Convite*/
if (document.frm_item.convite!=undefined){
if (document.frm_item.convite.length==undefined){
var v_unitario = document.getElementById('vlr_conv_' + document.frm_item.convite.value);
if ( document.frm_item.convite.checked == true){
v_total_conv += v_unitario.value * 1;
}
}
else{
for (i = 0; i < document.frm_item.convite.length; i++){
var v_unitario = document.getElementById('vlr_conv_' + document.frm_item.convite[i].value);
if ( document.frm_item.convite[i].checked == true){
v_total_conv += v_unitario.value * 1;
}
}
}
v_total += v_total_conv
v_total_conv = (v_total_conv.toString()).replace(".", ",")
if(v_total_conv.indexOf(',') < 0) { v_total_conv += ',00'; }
document.getElementById('vlr_convite').innerHTML = "Total em ingresso: <b>R$ " + v_total_conv + "</b>";
}
/*Atualizando Total*/
v_total = (v_total.toString()).replace(".", ",")
if(v_total.indexOf(',') < 0) { v_total += ',00'; }
document.getElementById('vlr_total').innerHTML = "TOTAL do pacote: <b>R$ " + v_total + "</b>";
}
Todas as Respostas
-
Vamos lá ...
1 - Jquery é um framework javascript, e nao uma linguagem, não ha problema algum misturar códigos "Javascript classícos" com "códigos em jquery ...
2 - Partindo deste presuposto, se você manteve a sua função principal intacta, e mudou somente a "chamada para a função", e esta chamada está correta, logo nao deverá ocorrer erros ...
3 - Voce está fazendo a chamada de forma errada ....
$('#radio2').change({AtualizaValorTotal()}); ....4 - Observei que sua funcao principal, está lendo inputs pelo ID -> var v_unitario = document.getElementById . Te pergunto, ao seus checkboxes, vc manteve o ID deles?
- Sugerido como Resposta Eduardo Perotta de Almeida sábado, 22 de outubro de 2011 00:35