Why are the letters being printed individually ? and not the words of the array as "SAMSUNG" for example?

Asked

Viewed 71 times

0

var controle;
var index = 0;
function escolheControle(c) {   
    controle = c;
    marca =todasAsmarcas[controle];
    window.location= "marcaWebkit.htm?contMenu="+contMenu+"&marca="+todasAsmarcas[controle]+"&controle="+c+"&index="+index; 
    console.log(controle+' controle-----');
    console.log(todasAsmarcas+' todasAsmarcas-----');
}

var marca; 
var todasAsmarcas = new Array(4);
todasAsmarcas[0] = new Array("Samsung", "LG", "Sony", "SempToshiba", "Panasonic", "AOC", "CCE", "Philips", "Sharp", "Toshiba", "Gradiente", "Philco", "Buster", "Semp", "Hitachi", "Sanyo", "Blue Sky", "Mitsubishi", "Aiko", "Cineral", "JVC", "Zenith");
todasAsmarcas[1] = new Array("Samsung", "LG", "Sony", "SempToshiba", "Panasonic", "AOC", "CCE", "Philips", "Sharp", "Toshiba", "Gradiente", "Philco", "Buster", "Hitachi", "Sanyo", "Blue Sky", "Mitsubishi", "Aiko", "Cineral", "JVC", "Zenith");
todasAsmarcas[2] = new Array("Samsung", "LG", "Sony", "SempToshiba", "Panasonic", "AOC", "CCE", "Philips", "Sharp", "Toshiba", "Gradiente", "Philco", "Buster", "Hitachi", "Sanyo", "Blue Sky", "Mitsubishi", "Aiko", "Cineral", "JVC", "Zenith");
todasAsmarcas[3] = new Array("Samsung", "LG", "Sony", "SempToshiba", "Panasonic", "AOC", "CCE", "Philips", "Sharp", "Toshiba", "Gradiente", "Philco", "Buster", "Semp", "Hitachi", "Sanyo", "Blue Sky", "Mitsubishi", "Aiko", "Cineral", "JVC", "Zenith");

function initial(x) {           
    document.getElementById("estiloId1").value=marca[index];            
    console.log(marca+"  MARCA---------");
    console.log(index+"  MEU INDEX--------");
    console.log(marca[index]+" MARCA + INDEX--------");
}

//------------------------------------------------CODE marcaWebkit.htm

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-9">
<link href="webkit_CSS/menuWebkit1.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="controle.js"></script>      
<script type="text/javascript">
  window.onload = function(){           
     document.getElementById("img1").classList.add("menuHighlightON");
     console.log("teste");        
 }      
</script>   
</head>
<body >
<div id="myFrame" name="main">  
<div id="myDoc">
<p id=firstP>Pressione CONFIRMA na imagem correspondente ao controle remoto 
que deseja configurar para operar sua TV.</p>
    <img id="esq" name="esq" src="img/esq.png">
    <a href="#"  onclick="escolheControle(0)"><input type="image" id ="img1" 
name ="img1" src="img/transp.png"></a>
    <a href="#" onclick="escolheControle(1)"><input type="image" id ="img2" 
name ="img2" src="img/transp.png"></a>
    <a href="#" onclick="escolheControle(2)"><input type="image" id ="img3" 
name ="img3" src="img/transp.png"></a>
    <a href="#" onclick="escolheControle(3)"><input type="image" id ="img4" 
name ="img4" src="img/transp.png"></a>      
    <img id="dir" name="dir" src="img/dir.png">     
</div>
</div>      
<script src="http://webapp.local/apps/samba-ui/iapps-lib.min.js"></script>  
<script src="webkit_JS/indexWebkit.js"></script> 
</body> 
</html>

Logs for analysis

Samsung,LG,Sony,Semptoshiba,Panasonic,AOC,CCE,Philips,Sharp,Toshiba,Gradiente,Philco,Buster,Hitachi,Sanyo,Blue Sky, Mitsubishi, Aiko, Cineral, JVC, Zenith MARCA-------------- marcaWebkit.js:40

1 MY INDEX------- marcaWebkit.js:41

THE MARK + INDEX--------

  • Because several arrays containing almost repeated values ? Wouldn’t it be better to create only one object ?

  • Not repeated , each has a different amount .

  • Certainty ? The first with the last are equal, the second with the third too! Wouldn’t it be better to create only one object and access by name ? Because you can’t understand what you’re trying to do! Yeah marca = todasAsmarcas[controle]; will never bring the result you expect, because the index is returning, and all are array, in case it would have to inform another index todasAsmarcas[0][1]; see this example: http://jsbin.com/basoviriki/edit?js,console

  • Correcting: create just one array and access through index, for what I understand is what you are trying to do. See: http://jsbin.com/mapadaqami/edit?js,console

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.