[Javascript] (no subject)

Grinwald, Uri UGrinwald at dynamic.ca
Mon Dec 15 14:54:14 CST 2003


Hi everyone.
Just joined your group and looking forward to tapping into this new resource.
Thanks.

I need some assistance in  validating a form whereby a relationship exist between two fields.

Here is the scenario.

I have three radio language (rad but) for English, French, and Both.
Below I have a txt field for Quantity English and another for Quantity French.

I can validate these fields seperately using functions such as making sure one of the language rad buttons is checked, but I would like to make a condition by where if the eng rad but is checked then the EngQuantity is required or if the French Rad But is checked then the French Quantity is required and last if the Both Rad button is checked than, make sure that both Quantity Eng and French are required.


Here are my individual function to make sure that at least one radio button is checked and that the field is not empty.

function isThereOneChecked(oRadio)
{
	radioOption = -1
	for(var i=0;i<oRadio.length;i++)
	{
	if (oRadio[i].checked)
		{
			radioOption = i
			return true;

		}
	}
	return false;
}


function IsEmpty(s)
{
	if ((s==null) || (s=="") || (s== " "))
		{return true;}
	else
		{return false;}

}

In my function(Validate(obj)) I first check to make sure that a language is chosen

if (! isThereOneChecked(obj.a50_Language))
{
msgError = msgError + '\n' + 'You must pick a language';
}

if msgError != '')
{
alert (blah)
return false ;
}

This is as far as I can get. How do I now dpending on their choice of language set up avalidation for quantity fields?

Beloe is the snippet of HTML in form

<tr>
      <td>&nbsp;</td>
      <td valign="middle"><input type="radio" name="a50_Language" value="english">
          English 
          <input type="radio" name="a50_Language" value="french">
          French 
          <input type="radio" name="a50_Language" value="both">
      Both      </td>
      <td><span class="headertext">English 
        <input name="a60_Qnty_English" type="text" size="8">
French 
<input name="a70_Qnty_French" type="text" size="8">
</span></td>
    </tr>


Any help would be most appreciated.
I tried acouple of methods but I am getting errors across the board.
Here is my full albeit disfunctional code givivng me errors.

function isThereOneChecked(oRadio)
{
	radioOption = -1
	for(var i=0;i<oRadio.length;i++)
	{
	if (oRadio[i].checked)
		{
			radioOption = i
			return true;

		}
	}
	return false;
}

function languageSelected
for (var i = 0; i < obj.a50_Language.length; i++){
      if (obj.a50_Language[i].checked)
	  	{
         languageselected =obj.a50_Language[i].value
		}
}
function IsEmpty(s)
{
	if ((s==null) || (s=="") || (s== " "))
		{return true;}
	else
		{return false;}

}
function Validate(obj)
	{
	// var declarations
   var msgError = '';
	if (!chkSelection(obj.a10_Select_Region))
 	{
 		msgError = msgError + '\n' + 'Please select a Region';
 	}

	if (!chkSelection(obj.a20_Requested_By))
 	{
 		msgError = msgError + '\n' + 'Who was this requested by?';
 	}
	if(IsEmpty(obj.a30_Required_by_Date.value) )
	{
	msgError = msgError + '\n' + 'A required date must be provided';
	}
	else

	if(!testDate(obj.a30_Required_by_Date) )
	{
	msgError = msgError + '\n' + 'Write a valid  required date';
	}

	if(!isThereOneChecked(obj.a50_Language))
	{
	msgError = msgError + '\n' + 'You must pick a language';
	}
	else
	 
   if(languageSelected=="english")){
	if(IsEmpty(obj.a60_Qnty_English.value) )
	{
	msgError = msgError + '\n' + 'You must provide english quantity';
	}
else
	if(languageSelected="french")){
	if(IsEmpty(obj.a70_Qnty_French.value) )
	{
	msgError = msgError + '\n' + 'You must provide french quantity';
	}
else
	if(languageSelected="both")){
	if(IsEmpty(obj.a60_Qnty_English.value || obj.a70_Qnty_French.value) )
	{
	msgError = msgError + '\n' + 'You must provide both an English and French quantity';
	}
			}
		}
	}
}
	if (msgError != '')
	{
		alert('There was a problem with your submission: \n\n' + msgError + '\n\nPlease change your input and submit again.' )
		return false ;
	}

}//end of Validate function


Uri Grinwald
Web Designer
Dynamic Mutual Funds
55th Floor, Scotia Plaza
40 King Street West
Toronto, ON M5H 4A9
Phone: 416-365-2437
Fax: 416-365-5602



More information about the Javascript mailing list