Jump to content

[SOLVED] help with this script


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>

Link to comment
https://forums.phpfreaks.com/topic/149620-solved-help-with-this-script/
Share on other sites

The '===' means an identical comparison - not just evaluated equal. In other words, the values are just not "evaluated" as equal - they are exactly identical. A few examples should explain clearly:

if (1 == true) //result is true (a 1 is evaluated as true)
if (1 == 1) //result is true
if (1 === true) //result is false (they are not the same type)
if (1 === 1) //result is true

 

This PHP manual page should help as well: http://us3.php.net/operators.comparison

 

 

As for the code tags, you can simply select the PREVIEW button to get your post in a form where you can insert them with the available tools, or just put these around your code (without spaces) and it will display like my examples above:

 

[ c o d e ]code goes here[ / c o d e ]

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.