1 <!DOCTYPE HTML PUBLIC
"-//W3C//DTD HTML 4.0//EN">
6 <style type=
"text/css">
9 font-family: verdana
, sans-serif
;
29 text-decoration:underline
;
34 text-decoration: none
;
47 border-bottom-width:1px;
48 border-bottom-style:dotted
;
64 <table width=
"90%" border=
"0" cellspacing=
"1" cellpadding=
"5">
67 <big><tt>Global.helma.Html.prototype.dropDown
(param,
options,
selectedValue,
firstOption)
</tt></big><br>
73 Renders a x/html drop down select box
<br><br>
76 <li><b>Parameter
</b> <code>{Object}
</code>:
<br/>
77 param An object containing the tag attributes
<li><b>Parameter
</b> <code>{Array}
</code>:
<br/>
78 options Either an array of strings, an array with several
<code>{value: v, display: d}
</code> objects, or a collection of
<code>[
"value",
"display"]
</code> arrays in an array
<li><b>Parameter
</b> <code>{String}
</code>:
<br/>
79 selectedValue The value to pre-select
<li><b>Parameter
</b> <code>{String}
</code>:
<br/>
80 firstOption An optional first option to display in the select box (this option will always have no value)
91 <table width=
"90%" border=
"0" cellspacing=
"1" cellpadding=
"5">
93 <td>Sourcecode in /root/helma-
1.6.1/modules/helma/Html.js:
94 <pre><font color=
"#aaaaaa">463:
</font> helma.Html.prototype.dropDown = function(param, options, selectedValue, firstOption) {
95 <font color=
"#aaaaaa">464:
</font> if (!param) {
96 <font color=
"#aaaaaa">465:
</font> res.write(
<font color=
"#9999aa">"[Html.dropDown: insufficient arguments]
"</font>);
97 <font color=
"#aaaaaa">466:
</font> return;
98 <font color=
"#aaaaaa">467:
</font> }
99 <font color=
"#aaaaaa">468:
</font> var attr = Object.prototype.reduce.call(param);
100 <font color=
"#aaaaaa">469:
</font> if (!attr.size)
101 <font color=
"#aaaaaa">470:
</font> attr.size =
1;
102 <font color=
"#aaaaaa">471:
</font> this.openTag(
<font color=
"#9999aa">"select
"</font>, attr);
103 <font color=
"#aaaaaa">472:
</font> res.write(
<font color=
"#9999aa">"\n
"</font>);
104 <font color=
"#aaaaaa">473:
</font> if (firstOption) {
105 <font color=
"#aaaaaa">474:
</font> this.openTag(
<font color=
"#9999aa">"option
"</font>, {value:
<font color=
"#9999aa">""</font>});
106 <font color=
"#aaaaaa">475:
</font> res.write(firstOption);
107 <font color=
"#aaaaaa">476:
</font> this.closeTag(
<font color=
"#9999aa">"option
"</font>);
108 <font color=
"#aaaaaa">477:
</font> res.write(
<font color=
"#9999aa">"\n
"</font>);
109 <font color=
"#aaaaaa">478:
</font> }
110 <font color=
"#aaaaaa">479:
</font> for (var i in options) {
111 <font color=
"#aaaaaa">480:
</font> var attr = new Object();
112 <font color=
"#aaaaaa">481:
</font> var display =
<font color=
"#9999aa">""</font>;
113 <font color=
"#aaaaaa">482:
</font> if ((options[i] instanceof Array)
&& options[i].length
> 0) {
114 <font color=
"#aaaaaa">483:
</font> <font color=
"#33aa00"> // option is an array
115 <font color=
"#aaaaaa">484:
</font> </font> attr.value = options[i][
0];
116 <font color=
"#aaaaaa">485:
</font> display = options[i][
1];
117 <font color=
"#aaaaaa">486:
</font> } else if (options[i].value != null
&& options[i].display != null) {
118 <font color=
"#aaaaaa">487:
</font> <font color=
"#33aa00"> // option is an object
119 <font color=
"#aaaaaa">488:
</font> </font> attr.value = options[i].value;
120 <font color=
"#aaaaaa">489:
</font> if (options[i][
<font color=
"#9999aa">"class
"</font>] != null) {
121 <font color=
"#aaaaaa">490:
</font> attr[
<font color=
"#9999aa">"class
"</font>] = options[i][
<font color=
"#9999aa">"class
"</font>];
122 <font color=
"#aaaaaa">491:
</font> }
123 <font color=
"#aaaaaa">492:
</font> display = options[i].display;
124 <font color=
"#aaaaaa">493:
</font> } else {
125 <font color=
"#aaaaaa">494:
</font> <font color=
"#33aa00"> // assume option is a string
126 <font color=
"#aaaaaa">495:
</font> </font> attr.value = i;
127 <font color=
"#aaaaaa">496:
</font> display = options[i];
128 <font color=
"#aaaaaa">497:
</font> }
129 <font color=
"#aaaaaa">498:
</font> if (helma.Html.isSelected(attr.value, selectedValue))
130 <font color=
"#aaaaaa">499:
</font> attr.selected =
<font color=
"#9999aa">"selected
"</font>;
131 <font color=
"#aaaaaa">500:
</font> this.openTag(
<font color=
"#9999aa">"option
"</font>, attr);
132 <font color=
"#aaaaaa">501:
</font> res.write(display);
133 <font color=
"#aaaaaa">502:
</font> this.closeTag(
<font color=
"#9999aa">"option
"</font>);
134 <font color=
"#aaaaaa">503:
</font> res.write(
<font color=
"#9999aa">"\n
"</font>);
135 <font color=
"#aaaaaa">504:
</font> }
136 <font color=
"#aaaaaa">505:
</font> this.closeTag(
<font color=
"#9999aa">"select
"</font>);
137 <font color=
"#aaaaaa">506:
</font> res.write(
<font color=
"#9999aa">"\n
"</font>);
138 <font color=
"#aaaaaa">507:
</font> return;
139 <font color=
"#aaaaaa">508:
</font> }