Gossamer Forum
Home : Products : DBMan : Customization :

Build a select fields dependent upon a key field's contents

Quote Reply
Build a select fields dependent upon a key field's contents
I've been using the Multiple Select Fields Mod -- allowing users to input several items from a drop-down list in one field. It's great!

Now I've got another need. I've defined 20 select menus in the .cfg file. Each one corresponds to one of 20 values for a field called "Topic" (the user choosing the value from a simple select menu).

Now, if the user has chosen Topic 20, I want to display Select Menu 20 (with a series of questions which match the topic) ... and so forth for the 20 Topics.

So I'm trying the following in the .pl file to display the select menu:

if ($rec{'Topic'} eq "$topic20") {
 |; print &build_select_field("Qn20", "$rec{'name_of_field_here'}");
} print qq|

-- having tried to define the select menu as Qn20 in the .cfg file. But this definition in .cfg gets rejected because it's not itself a field.

I'd really appreciate some guidance on how I might resolve this.

TIA,

Andy

[This message has been edited by Andy (edited November 27, 1999).]

[This message has been edited by Andy (edited November 27, 1999).]

[This message has been edited by Andy (edited November 27, 1999).]
Quote Reply
Re: Build a select fields dependent upon a key field's contents In reply to
Go Go Gadget Javascript!! You will have to use javascript to do this. There are a few Threads in this Forum that discuss how to do this.

Regards,

------------------
Eliot Lee
Anthro TECH,L.L.C
www.anthrotech.com
----------------------


Quote Reply
Re: Build a select fields dependent upon a key field's contents In reply to
Eliot, thanks for the guidance. I've now searched to an even greater depth than before and found one long thread on the topic you're referring to. It deals with a situation where a user makes a choice from one select field and then a second select list changes on-the-fly according to what's currently highlighted in the first list.

And I now realise that my posting wasn't sufficiently clear in stating what I'd done. I'm sorry for that.

Rather than having to use JavaScript or some other form of scripting with DBMan to make changes to a form based on current input in that same form, I've gone the simplistic route. On adding a form, the user makes a choice for the first select field and is then forced to create a record before getting access to the second list. So, in picking out a select list for the second choice, there's no need to look on-the-fly to what's chosen in the first list, but simply to check which one of 20 values was chosen from the first list.

I'm hoping this can avoid Javascript. Can I simply define my 20 drop-down lists in .cfg (but away from the "select fields" definition) and call on each one in .pl with a conditional statement that builds the right select list (number 20 if the corresponding name 20 was selected for the first select field) with this select list pointing to the same field in each case? Or am I barking up the wrong tree?

I'd really appreciate some comfort and direction on this!

TIA,

Andy
Quote Reply
Re: Build a select fields dependent upon a key field's contents In reply to
Again...the only way I can see that you can do this to build select fields conditionally is to use Javascript!

Good luck!

Regards,

------------------
Eliot Lee
Anthro TECH,L.L.C
www.anthrotech.com
----------------------


Quote Reply
Re: Build a select fields dependent upon a key field's contents In reply to
Eliot, thanks for keeping me thinking on this one.

I've looked thru' the Javascript select field thread -- and now think I've worked out a solution. It works as far as displaying the select field and saving the field input to the database file (for both the question selected and the answer textarea box), but when I return to modify the record subsequently, the fields from the database are not brought into the text boxes.

I can't see where I've gone wrong here. Or is my error elsewhere in the script?

Any further guidance would be really appreciated.

TIA,

Andy


Code added to sub html_record_form -----------------------------


for (my $i =1; $i <= 17; $i++) {

# display question set which matches topic number

if ($rec{'Topic'} eq $topic20)) {
print qq|
<select name="Question_$i" size="1">
<option>---</option>
<option>question 1 here</option>
<option>question 2 here</option>
<option>question 3 here</option>
</select>
<TEXTAREA NAME="Answer_$i" ROWS="3" COLS="60" WRAP="VIRTUAL" MAXLENGTH="7500">$rec{'Answer_$i'}</TEXTAREA>
|;
}

# similar question sets to be built for each other topic number

}


[This message has been edited by Andy (edited November 29, 1999).]
Quote Reply
Re: Build a select fields dependent upon a key field's contents In reply to
I've played with this some more and realise that some errors had crept into my .pl file, which I have now corrected.

Now I've tested things once more. In viewing the source of the page created with the above code, I see that it's placing the field values in NAME="Text_$i" but NOT in VALUE="$rec{'Text_$i'}" -- here, I'm just getting VALUE="" !

Have I just proved the point that DBMan itself can't handle this and Javascript is required? Or have I just messed up in writing the above code?

Thanks and much appreciation,

Andy