simpli Posted March 24, 2009 Share Posted March 24, 2009 Hi, I've been struggling with assigning data that comes from input textboxes to an array. Very simply, I have six input boxes that I put data in and I want to retrieve then upon submit for treatment. This doesn't seem to be working as I get a msgbox with 'object HTMLInputElement]'. I don't really know what the problem is as I have no error messages from the console and no real way to troubleshoot what's going on. Thanks for any help in advancing this, J-R <script type='text/javascript'> function formValidator(){ // Make quick references to our fields var p1 = document.frmchoixronde1.player_1; var p2 = document.frmchoixronde1.player_2; var p3 = document.frmchoixronde1.player_3; var p4 = document.frmchoixronde1.player_4; var p5 = document.frmchoixronde1.player_5; var p6 = document.frmchoixronde1.player_6; alert(p1); var arrayPlayers = []; arrayPlayers[0] = p1; arrayPlayers[1] = p2; arrayPlayers[2] = p3; arrayPlayers[3] = p4; arrayPlayers[4] = p5; arrayPlayers[5] = p6; alert(arrayPlayers[0]); } </script> <form id="frmchoixronde1" name="frmchoixronde1" method="POST" enctype="application/x-www-form-urlencoded" onsubmit='return formValidator()'> <html><head><title>Page des poolers</title></head> <body> <b>Entrez vos choix pour la premiere ronde</b> </br><fieldset> <b><label for="player_1" style="width:2em">1</label></b><input name="player_1" id="player_1" type="text" size="30"></br> <b><label for="player_2" style="width:2em">2</label></b><input name="player_2" id="player_2" type="text" size="30"></br> <b><label for="player_3" style="width:2em">3</label></b><input name="player_3" id="player_3" type="text" size="30"></br> <b><label for="player_4" style="width:2em">4</label></b><input name="player_4" id="player_4" type="text" size="30"></br> <b><label for="player_5" style="width:2em">5</label></b><input name="player_5" id="player_5" type="text" size="30"></br> <b><label for="player_6" style="width:2em">6</label></b><input name="player_6" id="player_6" type="text" size="30"></br> <input type="submit" name="submit" value="Soumettre vos choix"> </form> </br> </body></html> Quote Link to comment Share on other sites More sharing options...
rhodesa Posted March 24, 2009 Share Posted March 24, 2009 document.frmchoixronde1.player_1 will return the INPUT element...to get it's value, you need: document.frmchoixronde1.player_1.value Quote Link to comment Share on other sites More sharing options...
rhodesa Posted March 24, 2009 Share Posted March 24, 2009 also...you can make things easier with arrayed inputs and loops: <script type='text/javascript'> function formValidator(){ var arrayPlayers = new Array(); var form = document.frmchoixronde1; for(var n=0;n < form.length;n++){ if(form[n].name == 'player[]') arrayPlayers.push(form[n].value); } alert(arrayPlayers.join(',')); return false; } </script> <form id="frmchoixronde1" name="frmchoixronde1" method="POST" enctype="application/x-www-form-urlencoded" onsubmit='return formValidator();'> <html><head><title>Page des poolers</title></head> <body> <b>Entrez vos choix pour la premiere ronde</b> </br><fieldset> <b><label for="player_1" style="width:2em">1</label></b><input name="player[]" id="player_1" type="text" size="30"></br> <b><label for="player_2" style="width:2em">2</label></b><input name="player[]" id="player_2" type="text" size="30"></br> <b><label for="player_3" style="width:2em">3</label></b><input name="player[]" id="player_3" type="text" size="30"></br> <b><label for="player_4" style="width:2em">4</label></b><input name="player[]" id="player_4" type="text" size="30"></br> <b><label for="player_5" style="width:2em">5</label></b><input name="player[]" id="player_5" type="text" size="30"></br> <b><label for="player_6" style="width:2em">6</label></b><input name="player[]" id="player_6" type="text" size="30"></br> <input type="submit" name="submit" value="Soumettre vos choix"> </form> </br> </body></html> Quote Link to comment Share on other sites More sharing options...
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.