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
Share on other sites

I dont understand the '===' operator. What does it do and why should i use it here.. Also what do you mean when you say to use the code tag? I dont know what it is so if I am being rude please accept appologies. Thank you for explaining etiquette.

 

J-R

Link to comment
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 ]

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.