Jump to content

Do document.getElementById and formObj[] work together?


simpli

Recommended Posts

Hi,

I have a form which i am trying to validate. There are txtfields and radio buttons. The text field validates fine. However when i try to validate the radiobutton nothing works. I am using document.getElementById() to get the text fields and formObj[] to get the radio buttons. They don't seem to work well together but I do not know if that is caused by something else in my script or some javascript specific issue. Can you tell me what is wrong below? Also is there a reason to use one function over the other?

 

Thank you kindly,

J-R

 

<script type='text/javascript'>

 

function formValidator(){

// Make quick references to our fields

var p10 = document.getElementById('player_10');

var matchup1 = formObj['1vs8East'];

 

// Validation of the text fields!

if(notEmpty(p10, "Votre Joueur #10 n'a pas ete choisi")){

if(radioselected(matchup1)){

return true;

}

 

}

 

return false;

 

}

 

function notEmpty(elem, helperMsg){

if(elem.value.length == 0){

alert(helperMsg);

elem.focus(); // set the focus to this input

return false;

}

return true;

}

 

function radioSelected(radioGrp)

{

 

alert("in validation");

  if (radioGrp.length)

  {

      //There are 2 or more options

      for (var i=0; i<radioGrp.length; i++)

      {

        if (radioGrp.checked) { return true; }

      }

      //No options were checked

      return false;

  }

  else

  {

      //There is only 1 option

      return radioGrp.checked;

  }

}

</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><legend>East</legend>

<label for="1vs8East_1"><input name="1vs8East" type="radio" id="1vs8East_1" value="Boston">Boston</label>

<label for="1vs8East_2"><input name="1vs8East" type="radio" id="1vs8East_2" value="Buffalo">Buffalo</label><br/>

</fieldset><br/><fieldset><b><label for="player_10" style="width:2em">10</label></b><input name="player_10" id="player_10" type="text" size="30"><br/></fieldset><input type="submit" name="submit" value="Soumettre vos choix"></form>

<br/>

</body></html>

 

 

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.