Gossamer Forum
Home : Products : DBMan : Customization :

How to build a conditional field

Quote Reply
How to build a conditional field
I'm another newbie to DBMan and Perl, so please bear with me if I'm not using the correct terminology.

From what I've read it sounds like I need a conditional field. I'm building a database of abstracts, and different types of abstracts have different fields associated with them.

http://www.ceri.memphis.edu/cgi-bin/db_ab/db.cgi?db=abstracts&uid=default&view_search=1

Since the field for the type of abstract is a radio field, the users can only select one type. However, they can still answer fields that aren't related to the type. I've color-coded the table cells for the different types of abstracts, but I think I'd better try to make it foolproof.

This is what the fields I'm talking about look like:

'Type' => [ 7, 'alpha', 0, 20, 1, '', ''],
'Prof_meet' => [ 8, 'alpha', 40, 255, 0, '', ''],
'Prof_date' => [ 9, 'alpha', 10, 10, 0, '', ''],
'Pub_name' => [10, 'alpha', 40, 255, 0, '', ''],
'Pub_date_sub' => [11, 'alpha', 10, 10, 0, '', ''],
'Pub_date_adm' => [12, 'alpha', 10, 10, 0, '', ''],
'Prop_ag' => [13, 'alpha', 20, 255, 0, '', ''],
'Prop_dead' => [14, 'alpha', 10, 10, 0, '', ''],
'Prop_resub' => [15, 'alpha', 0, 6, 0, '', ''],
'Prop_date_sub' => [16, 'alpha', 10, 10, 0, '', ''],
'Prop_start' => [17, 'alpha', 10, 10, 0, '', ''],
'Prop_dur' => [18, 'alpha', 20, 255, 0, '', ''],
'Thesprop_type' => [19, 'alpha', 0, 4, 0, '', ''],
'Thesprop_date' => [20, 'alpha', 10, 10, 0, '', ''],
'Thesprop_adv' => [21, 'alpha', 40, 255, 0, '', ''],
'Thes_type' => [22, 'alpha', 0, 4, 0, '', ''],
'Thes_date' => [23, 'alpha', 10, 10, 0, '', ''],
'Thes_adv' => [24, 'alpha', 40, 255, 0, '', ''],
'Coll_inst' => [25, 'alpha', 40, 255, 0, '', ''],
'Coll_date' => [26, 'alpha', 10, 10, 0, '', ''],
'Oth_descr' => [27, 'alpha', '40x5', 1000, 0, '', ''],

'Type' => 'Professional Meeting,Publication,Research Proposal,Thesis Proposal,Thesis,Colloquium,Other'

E.g., if the user selects Professional Meeting, the relevant fields are Prof_meet and Prof_date. If it's Publication, then Pub_name, Pub_date_sub, and Pub_date_adm. And so on.

Anyway, I've searched and looked through the forum and the FAQs and haven't run across a similar routine. Would someone be willing to help me get started with this? Or point me in the direction of a previous post?
Quote Reply
Re: [ktgis] How to build a conditional field In reply to
Are you using auto-generate?

If not you could use JavaScript to "disable" all other selections when someone picks Publication, etc.

Last edited by:

Watts: Jan 26, 2005, 2:54 PM
Quote Reply
Re: [Watts] How to build a conditional field In reply to
In your sub html_record you could use:

if ($rec{'Type'} eq "Professional Meeting") {
print qq| <list your fields here> |;
}

if ($rec{'Type'} eq "Publication") {
print qq| <list your fields here> |;
}

etc. for all the options for "Type"

For the add form you would need to have all the fields displayed or hidden to have the db run. I think your color coding is a good idea for that.

Unoffical DBMan FAQ

http://creativecomputingweb.com/dbman/index.shtml/
Quote Reply
Re: [LoisC] How to build a conditional field In reply to
Lois, Your suggestion works just fine. Thanks! And also thanks for the FAQs--they've allowed someone with no web database background to appear to the unwitting as someone who actually knows a thing or two!

Watts, I'm intrigued by your suggestion of using javascript to disable fields. Since I'm also javascript-stupid (but a willing learner) could you give me a clue?
Quote Reply
Re: [ktgis] How to build a conditional field In reply to
Code:
<HTML><HEAD><TITLE></TITLE>
<SCRIPT LANGUAGE="JavaScript">

function turnOff2() {
if (formxyz.box1.checked) {
formxyz.box2.disabled = true;
formxyz.select2.disabled = true;
description2.style.color = "gray";
}
else {
formxyz.box2.disabled = false;
formxyz.select2.disabled = false;
description2.style.color = "black";
}
}

function turnOff1() {
if (formxyz.box2.checked) {
formxyz.box1.disabled = true;
formxyz.select1.disabled = true;
description1.style.color = "gray";
}
else {
formxyz.box1.disabled = false;
formxyz.select1.disabled = false;
description1.style.color = "black";
}
}

</SCRIPT>
</HEAD>
<BODY BGCOLOR="#FFFFFF">

<FORM NAME="formxyz">

<P>Choose Only One Option and Color From the Sets Below:

<P><INPUT TYPE="checkbox" NAME="box1" VALUE="1" onClick="turnOff2();"><LABEL ID="description1">Option One:</LABEL>
<SELECT NAME="select1">
<OPTION VALUE="blue">blue</OPTION>
<OPTION VALUE="green">green</OPTION>
<OPTION VALUE="red">red</OPTION>
</SELECT>

<P><INPUT TYPE="checkbox" NAME="box2" VALUE="1" onClick="turnOff1();"><LABEL ID="description2">Option Two:</LABEL>
<SELECT NAME="select2">
<OPTION VALUE="black">black</OPTION>
<OPTION VALUE="white">white</OPTION>
<OPTION VALUE="tan">tan</OPTION>
</SELECT>

</FORM>

</BODY>
</HTML>

Here is a sample page - not sure how cross-browser compatible it is, but since I have a captive audience I only need it to work on IE 6+.

Play around with it. Good luck!
Quote Reply
Re: [Watts] How to build a conditional field In reply to
Wow! Thank you so much. I won't have much time to play around with it cause I'm going out of town tomorrow but I'll get back to you next week and let you know how it works. Can't wait to try it out.

You guys are the best!
Quote Reply
Re: [Watts] How to build a conditional field In reply to
OK Watts, I've built the form as you suggested and now have the javascript working and it's just what I wanted. Thanks for the help!!

However, I'm not quite there yet. One thing is that the radio fields are still clickable. The URL of the test form is http://www.ceri.memphis.edu/test_ab/form.html. I'm attaching the javascript.

The other question is related to running a form with db.cgi as the action instead of from html.pl. Since users have to log in to add records, how do I set up the action?

Lois, your suggestion worked great too. Thanks!
Quote Reply
Re: [ktgis] How to build a conditional field In reply to
The disable script may not work with radio button.

Try giving the button input tag an "ID"

<INPUT TYPE="radio" NAME="bob" ID="bob"> and see if that helps any (kinda like you did with the labels"). Not sure...

http://www.ceri.memphis.edu/cgi-bin/db_ab/db.cgi

Use this to run the dbman script (check default.cfg to set up who has to log in and what they can do). Right now I get a dbman error when calling up the URL - must have something to do with the config file.