R_MontSerrat Posted September 28, 2012 Report Share Posted September 28, 2012 Boa tarde amigosNão estou conseguindo capturar o valor do select, só captura o primeiro valor.Segue o códigoHTML<select name="acompanhante" id="acompanhante" onchange="document.getElementById('white_content').style.display='block';document.getElementById('black_overlay').style.display='block;';return false;" > <option value="0">Sem acompanhantes</option> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> <option value="6">6</option> <option value="7">7</option> <option value="8">8</option> </select> Javascript <script LANGUAGE="JavaScript" TYPE="text/javascript"> <!-- var numero; indice = document.getElementById("acompanhante").selectedIndex; teste = document.getElementById("acompanhante").options[indice].value; document.write (teste); for (numero=1; numero<=teste; numero++){ document.write ("<input name=nome_acompanhante type=text value=acompanhante class=input2 />"+" "); } //--> </SCRIPT>Vocês podem me ajudar? Preciso disso urgentemente Quote Link to comment Share on other sites More sharing options...
0 Arash Posted September 28, 2012 Report Share Posted September 28, 2012 (edited) Eu sugiro a voce não usar document.write, por que voce não sabe em que lugar da página ele vai colocar, eu acho ruim esse método sei la. Se eu fosse voce colocava um <p> ou criava um com javascript, para abrigar esses campos.Usa o window.onload, e dentro coloca um document.getElementById("acompanhante").onchange = function (), para verificar toda vez que o select for alterado, e no for, voce não pode usar document.write, por que ele vai sobreescrever o input anterior!<!doctype html> <html> <head> <meta charset="utf-8"> <title>Documento sem título</title> <script> <!-- window.onload = function () { document.getElementById("acompanhante").onchange = function () { var numero, indice, teste; indice = document.getElementById("acompanhante").selectedIndex; teste = document.getElementById("acompanhante").options[indice].value; document.getElementById("o").innerHTML = teste + " - Acompanhantes<br>"; for (numero=0; numero<teste; numero++){ document.getElementById("o").innerHTML += "<input name='nome_acompanhante' type='text' placeholder='acompanhante' class='input2' />" + "<br>"; } } } //--> </SCRIPT> </head> <body> <select name="acompanhante" id="acompanhante" onchange="document.getElementById('white_content').style.display='block';document.getElementById('black_overlay').style.display='block;';return false;" > <option value="0">Sem acompanhantes</option> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> <option value="6">6</option> <option value="7">7</option> <option value="8">8</option> </select> <p id="o"></p> </body> </html> Edited September 28, 2012 by Arash Quote Link to comment Share on other sites More sharing options...
0 R_MontSerrat Posted September 28, 2012 Author Report Share Posted September 28, 2012 MUITO obrigado, consegui Quote Link to comment Share on other sites More sharing options...
Question
R_MontSerrat
Boa tarde amigos
Não estou conseguindo capturar o valor do select, só captura o primeiro valor.
Segue o código
HTML
JavascriptVocês podem me ajudar? Preciso disso urgentemente
Link to comment
Share on other sites
2 answers to this question
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.