Ir para conteúdo
Fórum Script Brasil
  • 0

funciona No Ff E Dá Pau No Ie


Guest wwrangel

Pergunta

Guest wwrangel

Gente... estou com um script aqui que esta me deixando louco..... é o seguinte ele funciona normalmente no FF mas quando vou testar no IE dá pau..

Aparece a msg :

'document.getElementById(...)' é nulo ou não é um objeto

É um carrinho de compras. No IE até que funciona, mas quando eu vou alterar a quantidade de um iten se coloco um valor novo vai beleza, mas se dou um refresh na pagina ou repito o mesmo valor ela dá essa msg acima.

Segue o codigo:

carrinho.js

function showItems()

{

var tablerowcolor = '#EBECED';

index = document.cookie.indexOf("RCAcarrinho");

countbegin = (document.cookie.indexOf("=", index) + 1);

countend = document.cookie.indexOf(";", index);

if (countend == -1) {countend = document.cookie.length;}

fulllist = document.cookie.substring(countbegin, countend);

totprice = 0;

totpeso = 0;

document.writeln('<FORM NAME="updateform">');

itemlist = 0;

for (var i = 0; i <= fulllist.length; i++)

{

if (fulllist.substring(i,i+1) == '[')

{

itemstart= i+1;

thisitem = 1;

}

else if (fulllist.substring(i,i+1) == ']')

{

itemend = i;

thequantity = fulllist.substring(itemstart, itemend);

itemtotal = 0;

itemtotal = (eval(theprice*thequantity));

temptotal = itemtotal * 100;

totprice = totprice + itemtotal;

itemtotpeso = 0;//-------------------------------------------------->

itemtotpeso = (eval(thepeso*thequantity));//------------------------>

temptotpeso = itemtotpeso * 100;//---------------------------------->

totpeso = totpeso + itemtotpeso;//------------------------------>

itemlist=itemlist+1;

document.write('<tr><td width=53px" valign="middle" class="tabela_car tabela_car_borda_esq"><div id="excluir1"><a href="java script:removeItem('+itemlist+')" title="Exclur '+theitem+'"><img src="images/car/img_del.gif" border="0" /></a></div></td>');

document.write('<td width="222px" valign="middle" class="tabela_car"><div class="titulocarrinho" id="iten1"><div id="textoiten1">'+thecod+' '+theitem+'</div></div></td>');

document.write('<td width="95px" valign="middle" class="tabela_car"><div class="titulocarrinho" id="valor1">R$'+theprice+'</div></td>');

document.write('<td width="55px" valign="middle" class="tabela_car"><div class="titulocarrinho" id="quantidade1"><input type=text name="quant'+itemlist+'" value="'+thequantity+'" size=3 class="formcarrinho" maxlength="3" onkeyup="amendItem('+itemlist+',document.formulario.quant'+itemlist+'.value)" /></div></td>');

//onkeyup="window.setTimeout(amendItem('+itemlist+',document.formulario.quant'+itemlist+'.value),1000);"/></div></td>');

//onkeyup="amendItem('+itemlist+',document.formulario.quant'+itemlist+'.value)" /></div></td>');

document.write('<td valign="middle" class="tabela_car tabela_car_borda_dir"><div class="titulocarrinho" id="subtotal1">R$ '+alterError(itemtotal)+'</div></td></tr>');

//submete para salvar

document.writeln('<INPUT TYPE="hidden" NAME="cod'+itemlist+'" VALUE="|'+thecod+'" SIZE="10" >');

//document.writeln('<INPUT TYPE="hidden" NAME="item'+itemlist+'" VALUE="|'+theitem+'"SIZE="40" >');

document.writeln('<INPUT TYPE="hidden" NAME="qtde'+itemlist+'" VALUE="|'+thequantity+'" SIZE="30">');

document.writeln('<INPUT TYPE="hidden" NAME="preço'+itemlist+'" VALUE="|'+theprice+'" SIZE="30" >');

document.writeln('<INPUT TYPE="hidden" NAME="total'+itemlist+'" VALUE="|'+alterError(itemtotal)+'">');

}

else if (fulllist.substring(i,i+1) == '|')

{

if (thisitem==1) thepeso = fulllist.substring(itemstart, i);//aqui...

if (thisitem==2) thecod = fulllist.substring(itemstart, i);//aqui...

if (thisitem==3) theitem = fulllist.substring(itemstart, i);

if (thisitem==4) theprice = fulllist.substring(itemstart, i);

thisitem++;

itemstart=i+1;

}

}

}

function amendItem(itemno, newquant)

{

var pesquisa = /^\d+$/;

if(!newquant.match(pesquisa) || newquant <= 0){

newquant = 1; //qtde default

alert("Por favor, a quantidade deve ser inteira, maior ou igual a 1!");

}

var newItemList = null;

itemlist = 0;

for (var i = 0; i <= fulllist.length; i++) {

if (fulllist.substring(i,i+1) == '[') {

thisitem = 1;

itemstart = i+1;

fullstart = i+1;

} else if (fulllist.substring(i,i+1) == ]') {

itemend = i;

itemlist=itemlist+1;

if (itemlist != itemno) {

newItemList = newItemList+ '['+fulllist.substring(fullstart, itemend)+']';

} else {

newItemList = newItemList + '['+thepeso+'|'+thecod+'|'+theitem+'|'+theprice+'|'+newquant+']'; //aqui...

}

} else if (fulllist.substring(i,i+1) == '|') {

if (thisitem==1) thepeso = fulllist.substring(itemstart, i);//aqui...

if (thisitem==2) thecod = fulllist.substring(itemstart, i);//aqui...

if (thisitem==3) theitem = fulllist.substring(itemstart, i);

if (thisitem==4) theprice = fulllist.substring(itemstart, i);

thisitem++;

itemstart=i+1;

}

}

index = document.cookie.indexOf("RCAcarrinho");

document.cookie=RCAcarrinho="+newItemList;

self.location = "carrinho.php";

}

function removeItem(itemno)

{

newItemList = null;

itemlist = 0;

for (var i = 0; i <= fulllist.length; i++)

{

if (fulllist.substring(i,i+1) == '[') {

itemstart = i+1;

} else if (fulllist.substring(i,i+1) == ]') {

itemend = i;

theitem = fulllist.substring(itemstart, itemend);

itemlist=itemlist+1;

if (itemlist != itemno) {

newItemList = newItemList+'['+fulllist.substring(itemstart, itemend)+']';

}

}

}

index = document.cookie.indexOf("RCAcarrinho");

document.cookie="RCAcarrinho="+newItemList;

self.location = "carrinho.php";

}

// clearBasket() - removes all items from the basket

function clearBasket()

{

if (confirm('Tem certeza que deseja limpar o seu carrinho de compras?')) {

index = document.cookie.indexOf("RCAcarrinho");

document.cookie="RCAcarrinho=.";

self.location = "carrinho.php";

}

}

function alterError(value)

{

if (value<=0.99) {

newPounds = '0';

} else

{

newPounds = parseInt(value);

}

newPence = parseInt((value+.0008 - newPounds)* 100);

if (eval(newPence) <= 9) newPence='0'+newPence;

newString = newPounds + '.' + newPence;

return (newString);

}

function alterErrorPeso(value)

{

if (value<=0.99) {

newPounds = '0';

} else {

newPounds = parseInt(value);

}

newPence = parseInt((value+.0008 - newPounds)* 1000);

if (eval(newPence) <= 9) newPence='0'+newPence;

newString = newPounds + '.' + newPence;

return (newString);

}

function calc_Cep()

{

return (newString);

}

///////////// FUNCOES REFERENTES AO CALCULO DO FRETE ////////////////////////////////////////////////////////////////////////////////

function pesquisa(peso)//Fun�o que monta a URL e chama a fun�o AJAX

{

//url="busca_frete.php?peso="+peso;

//url="busca_frete.php?peso="+peso+"&pedido="+totprice;

url="busca_frete.php?peso="+peso+"&pedido="+totprice+"&numItem="+itemlist;

ajax(url);

}

// Fun�o respons�el de conectar a uma p�ina externa e retornar os resultados, no nosso caso a busca_frete.php

function ajax(url)

{

req = null;

// Procura por um objeto nativo (Mozilla/Safari)

if (window.XMLHttpRequest)

{

req = new XMLHttpRequest();

req.onreadystatechange = processReqChange;

req.open("GET",url,true);

req.send(null);

}

// Procura por uma vers� ActiveX (IE)

else if (window.ActiveXObject)

{

req = new ActiveXObject("Microsoft.XMLHTTP");

if (req)

{

req.onreadystatechange = processReqChange;

req.open("GET",url,true);

req.send(null);

}

}

}

function processReqChange()

{

// apenas quando o estado for "completado"

if (req.readyState == 4)

{

// apenas se o servidor retornar "OK"

if (req.status ==200)

{

// procura pela div id="pagina" e insere o conteudo retornado nela, como texto HTML

document.getElementById('valortotal').innerHTML = req.responseText; //<--aqui �que configura-se a div que mostra o preso do frete

//document.getElementById('valortotal').firstChild = req.responseText;

}

else

{

alert("Houve um problema ao obter os dados:n" + req.statusText);

}

}

}

Link para o comentário
Compartilhar em outros sites

2 respostass a esta questão

Posts Recomendados

  • 0
Guest wwrangel

Deixem explicar melhor...Fiz um carrinho que esta funcionando beleza no FF só no IE que esta dando pau.

Quando vou alterar a quantidade de itens, se eu colocar uma quantidade que ainda não foi colocada para o iten funciona certinho ( tipo: esta 1 coloco 3 , beleza), mas se tento colocar uma quantidade já usada tipo 1 de novo da pau, ou então se eu dar F5 na pagina da pau também. Parece que os valores já usados ficam em cache.... O que eu posso fazer pra resolver isso, já tentei de tudo e não vai.......

Por favor me socorram......Valews

Link para o comentário
Compartilhar em outros sites

  • 0

po velho, postou o codigo todo zoado ai,

fica dificil de entender, e ai é dificil conseguir ajuda também.

olha só,

não consegui identificar qual dos teus metodos adiciona o valor repetido.

quando gera erro na tela, ele diz a linha do script que gerou o erro, alem de uma mensagem meio generica.

identifica ai nos teus metodos qual a linha que ta o erro.

eu vi que tu colocou ali, a mensagem:

'document.getElementById(...)' é nulo ou não é um objeto

notei também, que o unico momento que tu utiliza um getElementById, é dentro da funcao em AJAX.

depois do retorno com status = 200.

se tu postou todos os teus metodos em js.

então não sobrou muita alternativa, o erro é aquela unica linha que utiliza o getElementById.

sendo assim, era preciso dar uma olhada no teu codigo html.

onde esta sua div valortotal ???

ela existe no codigo, ou você cria dinamicamente?

e o retorno da sua funcao ajax?

já deu um alert em req.responseText pra ver o que esta retornando???

verifica ai,

t+

Link para o comentário
Compartilhar em outros sites

Participe da discussão

Você pode postar agora e se registrar depois. Se você já tem uma conta, acesse agora para postar com sua conta.

Visitante
Responder esta pergunta...

×   Você colou conteúdo com formatação.   Remover formatação

  Apenas 75 emoticons são permitidos.

×   Seu link foi incorporado automaticamente.   Exibir como um link em vez disso

×   Seu conteúdo anterior foi restaurado.   Limpar Editor

×   Você não pode colar imagens diretamente. Carregar ou inserir imagens do URL.



  • Estatísticas dos Fóruns

    • Tópicos
      152k
    • Posts
      651,7k
×
×
  • Criar Novo...