Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

QForms Check Box

Status
Not open for further replies.

murphyhg

Technical User
Mar 1, 2006
98
US
I am using the javascript API qforms for all of my form validation. Is there a way to see if a check box is checked in qforms and if it is make a radio group and a textfield required? Here is my checkbox code.

<input type="checkbox" name="arfedemployee" value="1" />
these are the form elements I want to make required if arfedemployee is checked.
<input type="radio" name="artermofaccess" value="1" />
<input type="radio" name="artermofaccess" value="0" />
<input type="text" name="arhowlongdetail">

Here is the code after the closing form tag
<SCRIPT LANGUAGE="JavaScript">
<!--//
objForm = new qForm("form1");
//not sure how to code this
if{(document.arfedemployee.form1 IS Checked)
objForm.artermofaccess.required = true;
objForm.arhowlongdetail.required = true;

}
//-->
</SCRIPT>
 
Thanks for your code. Here is the situation. The code does not work the first time I use the submit button. However, if I use the back button on the browser and then hit submit it works. My question is can I use some type of event handler on the check box to determine when if is clicked so the code between the if statement will be available when I click submit. Here is my code.

</form>
<!--// this code must execute after the end </FORM> tag //-->
<SCRIPT LANGUAGE="JavaScript">
<!--//
// replace "frmExample" with value of the <FORM> tag's NAME
// attribute. you can also substitute "objForm" with any
// variable name that makes sense for you
objForm = new qForm("form1");
// make sure the user has selected at least one of the following fields
qFormAPI.errorColor = "#a0c2e7";
objForm.araccounttype.description = "account type";
objForm.startdate.description = "email account start date";
objForm.arfirstname.description = "first name";
objForm.arlastname.description = "last name";
objForm.arlocation.description = "location";
objForm.arroom.description = "room number";
objForm.arofficephone.description = "office phone";
objForm.startdate.required = true;
objForm.araccounttype.required = true;
objForm.arfirstname.required = true;
objForm.arlastname.required = true;
objForm.arlocation.required = true;
objForm.arroom.required = true;
objForm.arofficephone.required = true;
if (document.forms['form1'].elements['arfedemployee'].checked) {
objForm.arorgcode.description = "organization code";
objForm.arorgcode.required = true;
objForm.artermofaccess.description = "term of access";
objForm.artermofaccess.required = true;
objForm.arhowlongdetail.description = "length of detail";
objForm.arhowlongdetail.required = true;
}
//-->
</SCRIPT>
 
Probably none of the highly skilled and generous folks who provide assistance on this forum use qForms since they just write validation themselves. Maybe Im wrong. The thing about components is that you must learn what they do so it is just like learning a new language. Well this is just my opinion and I know it is not helpful. Bottom line, a question about an API is best answered by the creators.

 
I was hoping that there was perhaps a Javascript programmer who had worked with QForms. I am not a javascript programmer so that is why I came to this site. Unfortunately, qforms does not have a forum. They do have documentation but it is above my head. If anyone can please help me solve this I am willing to pay for the services.
 
You might try adding an onclick event handler to the arfedemployee element.
Code:
...
<input type="" name="arfedemployee" onclick="setRequired(this, objForm);">
...
<script>
function setRequired( ff, objF ) {
   if( ff.checked ){
      objF.arorgcode.description = "organization code";
      objF.arorgcode.required = true;
      objF.artermofaccess.description = "term of access";
      objF.artermofaccess.required = true;
      objF.arhowlongdetail.description = "length of detail";
      objForm.arhowlongdetail.required = true; 
   } else {
      objF.arorgcode.required = false;         
      objF.artermofaccess.required = false;
      objF.arhowlongdetail.required = false; 
   }
}
</script>

The idea here is the onclick event handler is a function named setRequired() which you define. It takes two arguments, the first one, this, refers to the form element itself, the one which has the onclick event handler; the second one, objForm, is the qForm object which you have created in the code you posted.

Then the function determines whether the element is checked. If it is then it sets the properties of the qForm object which you passed in as an argument. Inside the function we refer to the qForm object by a different name just to keep things clear and general, objF is a local variable that exists within the function only.

If the element is not checked then we turn off the validation.

Just an idea. HTH

You might also spend some time on the pengo website reading about Create Custom Validation. It looks like that opens up the qForm object to your own validation rules.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top