@@ -17,10 +17,10 @@ function trim(value) {
1717function determineList ( ) {
1818 // generate a comma-separated list of the checked items
1919 var list = new String ( '' ) ;
20-
20+
2121 // either a checkbox object or an array of checkboxes
2222 var check = document . frm_help . check ;
23-
23+
2424 if ( ( check . length == undefined ) && ( check . checked != undefined ) ) {
2525 // only one checkbox on page
2626 if ( check . checked ) {
@@ -41,7 +41,7 @@ function determineList() {
4141 }
4242 }
4343 }
44- return list ;
44+ return list ;
4545}
4646
4747/**
@@ -160,7 +160,7 @@ function focusField(name) {
160160function selectField ( name ) {
161161 for ( i = 0 ; i < document . forms . length ; ++ i ) {
162162 var obj = document . forms [ i ] . elements [ name ] ;
163- if ( obj && obj . focus ) { obj . focus ( ) ; }
163+ if ( obj && obj . focus ) { obj . focus ( ) ; }
164164 if ( obj && obj . select ) { obj . select ( ) ; }
165165 }
166166}
@@ -203,3 +203,122 @@ function checkRequiredFields(fields)
203203 }
204204}
205205
206+ /**
207+ * seeks the given value (2nd argument)
208+ * in the value of the given input element (1st argument),
209+ * which is considered a list of values, separated by commas
210+ */
211+ function has_value ( input , val )
212+ {
213+ var actval = input . value
214+ var arr = feld . value . split ( ',' ) ;
215+ var max = arr . length ;
216+ for ( i = 0 ; i < max ; i ++ ) {
217+ if ( trim ( arr [ i ] ) == val ) {
218+ return true
219+ }
220+ }
221+ return false
222+ }
223+
224+ /**
225+ * Switch Value:
226+ * change the value of the given input field (might be of type text or hidden),
227+ * adding or removing the value of the given checkbox field (might be a radio
228+ * button as well)
229+ *
230+ * This function doesn't care whether or not the checkboxes of all values of
231+ * interest are present; but of course it doesn't have total control of the
232+ * text field.
233+ */
234+ function switch_val ( text , check )
235+ {
236+ var switched_val = check . value
237+ var arr = text . value . split ( ',' )
238+ var max = arr . length
239+ if ( check . checked ) {
240+ for ( i = 0 ; i < max ; i ++ ) {
241+ if ( trim ( arr [ i ] ) == switched_val ) {
242+ return
243+ }
244+ }
245+ if ( text . value )
246+ text . value = text . value + ',' + switched_val
247+ else
248+ text . value = switched_val
249+ } else {
250+ var neu = ''
251+ var changed = false
252+ for ( i = 0 ; i < max ; i ++ ) {
253+ if ( trim ( arr [ i ] ) == switched_val ) {
254+ changed = true
255+ } else {
256+ neu = neu + ',' + trim ( arr [ i ] )
257+ }
258+ }
259+ if ( changed ) {
260+ text . value = neu . substr ( 1 )
261+ }
262+ }
263+ }
264+
265+ /**
266+ * append the given value (2nd argument) to an input field
267+ * (1st argument) which contains comma-separated values;
268+ * see --> remove_val()
269+ *
270+ * This will work nicely even for batched lists
271+ */
272+ function append_val ( name , val )
273+ {
274+ var feld = document . itemSynopsis [ name ] ;
275+ var actval = feld . value ;
276+ if ( actval == '' ) {
277+ feld . value = val
278+ } else {
279+ var arr = feld . value . split ( ',' ) ;
280+ var max = arr . length ;
281+ for ( i = 0 ; i < max ; i ++ ) {
282+ if ( trim ( arr [ i ] ) == val ) {
283+ return
284+ }
285+ }
286+ feld . value = actval + ',' + val
287+ }
288+ }
289+
290+ /**
291+ * remove the given value (2nd argument) from the comma-separated values
292+ * of the given input element (1st argument); see --> append_val()
293+ */
294+ function remove_val ( name , val )
295+ {
296+ var feld = document . itemSynopsis [ name ] ;
297+ var actval = feld . value ;
298+ var changed = false ;
299+ if ( actval == '' ) {
300+ return
301+ } else {
302+ var arr = feld . value . split ( ',' ) ;
303+ var max = arr . length ;
304+ var neu = ''
305+ for ( i = 0 ; i < max ; i ++ ) {
306+ if ( trim ( arr [ i ] ) == val ) {
307+ changed = true
308+ } else {
309+ neu = neu + ',' + trim ( arr [ i ] )
310+ }
311+ }
312+ if ( changed ) {
313+ feld . value = neu . substr ( 1 )
314+ }
315+ }
316+ }
317+
318+ /**
319+ * give the focus to the element given by id
320+ */
321+ function focus2id ( name )
322+ {
323+ document . getElementById ( name ) . focus ( ) ;
324+ }
0 commit comments