javascript - Onchange doesn't work in second time -


People, I have a problem.

I have two functions which are selected after two collections of input boxes in the two selection boxes.

  & lt; Script type = "text / javascript" & gt; VetorCopiar = New Array (); Function copier () {// alert ("enter"); Formulario = document.getElementById ("preferencias"); Copiar = document.getElementById ("Copier"). Values; // warning ("Entrei"); Var input = document.getElementsByTagName ("input"); Var j = 0; (Var i = 0; i & lt; inputs.length; i ++) {if (inputs [i] .name.indexOf (copyier + '_') == 0) {// copier [i] = Input [i] name.indexOf (copiar + '_') value. VetorCopiar [j] = Input [i] .value; J ++; }} Return; } Function caller () {colar = document.getElementById ("colar"). Values; Var input = document.getElementsByTagName ("input"); Var j = 0; (Var i = 0; i & lt; inputs.length; i ++) {if (input [i] .name.indexOf (colar + '_') == 0) {document.getElementById (input [i ] .name). Value = vetorCopiar [J]; //alert(document.getElementById(inputs[i].name).value); // warning (vetorCopiar [ja]); J ++; }} Document.getElementById ("Copier"). Value = ""; Document.getElementById ("colar"). Value = ""; VetorCopiar = null; Return; } & Lt; / Script & gt; & Lt; P & gt; Copier Veer D & Lt; Span & gt; & Lt; Select name = "copier" id = "copier" onchange = "copier ();" & Gt; & Lt; Option selected = "selected" & gt; Die Cooper & lt; / Option & gt; & Lt; Option value = "segunda" & gt; Segunda & lt; / Option & gt; & Lt; Option value = "terracotta" & gt; Terca & lt; / Options & gt; & Lt; Option value = "quarta" & gt; Quarta & lt; / Option & gt; & Lt; Option value = "quinta" & gt; Quinta & lt; / Option & gt; & Lt; Option value = "sexta" & gt; Sexta & lt; / Options & gt; & Lt; Option value = "sabado" & gt; Sabado & lt; / Options & gt; & Lt; Option value = "domingo" & gt; Domingo & lt; / Options & gt; & Lt; / Select & gt; Paragraph & lt; Name Select name = "colar" id = "colar" onchange = "colar ();" & Gt; & Lt; Option selected = "selected" & gt; A colorful & lt; / Option & gt; & Lt; Option value = "segunda" & gt; Segunda & lt; / Option & gt; & Lt; Option value = "terracotta" & gt; Terca & lt; / Options & gt; & Lt; Option value = "quarta" & gt; Quarta & lt; / Option & gt; & Lt; Option value = "quinta" & gt; Quinta & lt; / Option & gt; & Lt; Option value = "sexta" & gt; Sexta & lt; / Options & gt; & Lt; Option value = "sabado" & gt; Sabado & lt; / Options & gt; & Lt; Option value = "domingo" & gt; Domingo & lt; / Options & gt; & Lt; / Select & gt; & Lt; / P & gt;  

For the first time this task is not completely the second time the problem does not work. Some help please

This does not work because you specify a value for the "colar" variable and by doing so Delete the function with the same name

Try to avoid using the same name on both id, functions and variables.

"colar_value" and "copiar_value" and "coliar" and "copper" should be "inner variables".

Sample:

  function Copier () {var formulario = document.getElementById ("preferencias"); var copiar_value = document.getElementById ("copier") value; var input = document. GetElementsByTagName ("input"); for var j = 0; Var i = 0; i & lt; inputs.length; i ++) {if (inputs [i] .name.indexOf (copier_value + '_') == 0) {witter copier [j] = input [i] Value; J ++;}} return;}  

and use to reset a selection:

  document.getElementById ("colar "). SelectedIndex = 0; Document.getElementById ("Copier"). SelectedIndex = 0;  

Comments