Gossamer Forum
Home : Products : DBMan : Customization :

passing attribute to sub build_select_field

Quote Reply
passing attribute to sub build_select_field
I'm sure this is covered somewhere in the forum, but I didn't see it.

If I want to produce the following:
Code:
<SELECT NAME="FIELD_22" ONCHANGE="functionName('FIELD_22', 'VALUE_2', 'VALUE_3')"><OPTION>--- etc. ...
AND
Code:
<SELECT NAME="FIELD_28" ONCHANGE="functionName('FIELD_28', 'VALUE_4', 'VALUE_7')"><OPTION>--- etc. ...
with the same function,

I believe the call would read something like this:

Code:
|; print &build_select_field ("FIELD_22", "$rec{'FIELD_22'}","ONCHANGE=\"functionName('FIELD_28', 'VALUE_4', 'VALUE_7')\"" ); print qq|
and the sub would read:
Code:
sub build_select_field {
# --------------------------------------------------------
# Builds a SELECT field based on information found
# in the database definition. Parameters are the column to build
# and a default value (optional).

my ($column, $value, $attributes) = @_;
my (@fields, $ouptut);

@fields = split (/\,/, $db_select_fields{$column});
if ($#fields == -1) {
$output = "error building select field: no select fields specified in config for field '$column'!";
}
else {
$output = qq|<SELECT NAME="$column" $attributes><OPTION>---\n|;
foreach $field (@fields) {
$field eq $value ?
($output .= "<OPTION SELECTED>$field\n") :
($output .= "<OPTION>$field\n");
}
$output .= "</SELECT>";
}
return $output;
}

I haven't tried it yet but am I on the right track?
beetlemanTongue

Marcus L. Griswold
Quote Reply
Re: [beetleman] passing attribute to sub build_select_field In reply to
Okay, so I just wasted my time by writing all of that down.

That is exactly how it is done.

Every day I prove to myself that I really am smarter that I think!Cool

Just a note, not adding an attribute to the call (ONCHANGE="....)
will simply omit such information from the select field when built.
Seperate subs need not be used for this feature.

Example:
Code:
|; print &build_select_field ("FieldName", "$rec{'FieldName'}", "ONCHANGE=\"functionName('FieldName', 'value1', 'value2')\""); print qq|

will return
Code:
<select name="FieldName" ONCHANGE="functionName('FieldName', 'value1', 'value2')"><option>---
<option>opt_1
<option>opt_2
...

but
Code:
|; print &build_select_field ("FieldName", "$rec{'FieldName'}", ); print qq|

will return
Code:
<select name="FieldName" ><option>---
<option>opt_1
<option>opt_2
...

Hope this helps anyone interested.
beetlemanTongue

Marcus L. Griswold