Jump to content

javascript array and the DOM


simpli

Recommended Posts

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> 

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.