submit() bij datepicker script?

Overzicht Reageren

Sponsored by: Vacatures door Monsterboard

Marco V

Marco V

01/02/2011 22:43:34
Quote Anchor link
Ik heb een leuk scriptleuk script gevonden dat ik wil gebruiken als datepicker, het script geeft een popup met een kalender, je prikt een datum en de datum gaat terug naar een tekstveld.

So far so good.

Nu wil ik het form waarin het tekstveld staat submitten zodra de waarde wordt gezet, dit laatste lukt me nog niet want onchange doet niks :-(

iemand nog een briljant idee?
 
PHP hulp

PHP hulp

24/11/2024 15:19:41
 
Ozzie PHP

Ozzie PHP

01/02/2011 22:51:29
Quote Anchor link
Hmmm.... laat ik eens in mijn glazen bol kijken...




oh nee, misschien is het handiger als jij eerst eens wat code post.
 
Jordi Kroon

Jordi Kroon

01/02/2011 22:52:56
Quote Anchor link
Graag alleen de relevante
 
Marco V

Marco V

01/02/2011 22:57:15
Quote Anchor link
Het is ook altijd hetzelfde met die gasten, vragen zonder code! :-)

Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php
/* --------------------------------- DE DATUM SELECTIE (DATEPICKER) ---------------------------------- */

// include the class (datepicker)

require ("/...datepicker/class.datepicker.php");    
// instantiate the object
$dp=new datepicker();

/* --------------------------------------------- FUNCTIES -------------------------------------------- */

// de functie (string) voot datepicker opstellen t.b.v. onclick event

function datepicker($dp,$veldnaam) {
    // de functie aanmaken
    $function=$dp->show($veldnaam);

    return $function;
}


// de datum selectie en een datumveld weergeven
function select_date($veldnaam,$datum,$dp) {
    // $veldnaam = de naam voor het tekstveld en de knop
    // $datum = de waarde voor het tekstveld
    // $dp = de functie voor datepicker
    
    // samenstellen van het onclick event bij de knop datepicker

    $onclick = datepicker($dp,$veldnaam);
    
    if ($datum == NULL) { $datum = "DD-MM-JJJJ"; }
    $selectdate = '<input name="'.$veldnaam.'" type="text" id="'.$veldnaam.'" value="'.$datum.'" size="10" maxlength="10" onchange="submit()"/> ';
    $selectdate .= '<input type="image" name="Selecteer_'.$veldnaam.'" id="Selecteer_'.$veldnaam.'" value="Selecteer_'.$veldnaam.'" src="/buttons/calendar.png" alt="selecteer een dag op de kalender" width="16" height="16" onclick="'.$onclick.'" />';

    return $selectdate;
}


/* ------- verderop in mijn script doe ik dit bij meerdere regels uit een while loop, zodoende komt er (waar aanwezig) een datum */

        // het datumveld voor STARTDD

        $STARTDD = select_date("STARTDD[".$regel."]",date2nl($PLANREGEL['STARTDD']),$dp);
        // het datumveld voor GEREEDDD
        $GEREEDDD = select_date("GEREEDDD[".$regel."]",date2nl($PLANREGEL['GEREEDDD']),$dp);
        
        

<
form action="" method="post" name="formplanregel" id="formplanregel<?php echo $regel; ?>" target="_self">
  <
tr [code]<?php echo $tr; ?>
>
    <td>&nbsp;</td>
    <td><?php echo $OMSCHRIJVING; ?></td>
    <td><?php echo $STARTDD; ?></td>
    <td><?php echo $GEREEDDD; ?></td>
    <td><?php echo $MEDEWERKER; ?></td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
</form>
?>
Gewijzigd op 01/02/2011 23:01:13 door Marco V
 
Jordi Kroon

Jordi Kroon

01/02/2011 23:02:09
Quote Anchor link
Onchange zou opzich moeten kuNnen

Onchange='this.form.submit();
 
Marco V

Marco V

01/02/2011 23:03:14
Quote Anchor link
ohh... ik had onchange=submit() gedaan... even testen! thx!

Toevoeging op 01/02/2011 23:08:14:

nope, geen succes... ik heb het zoals hieronder aangepast:

Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
<?php
if ($datum == NULL) { $datum = "DD-MM-JJJJ"; }
    $selectdate = '<input name="'.$veldnaam.'" type="text" id="'.$veldnaam.'" value="'.$datum.'" size="10" maxlength="10" Onchange="this.form.submit();"/> ';
    $selectdate .= '<input type="image" name="Selecteer_'.$veldnaam.'" id="Selecteer_'.$veldnaam.'" value="Selecteer_'.$veldnaam.'" src="/buttons/calendar.png" alt="selecteer een dag op de kalender" width="16" height="16" onclick="'.$onclick.'" />';
?>



Toevoeging op 01/02/2011 23:15:28:

p.s.: onchange werkt wel als ik handmatig iets type in het veld, mijn bedoeling is echter om ook als er via de datepicker een datum wordt gekozen (en dus automatisch de waarde van het veld wordt gevuld) dat er dan ook wordt gepost.
 
Niek s

niek s

02/02/2011 00:34:32
Quote Anchor link
dan moet je het event op de datepicker zetten.
 
Marco V

Marco V

02/02/2011 09:16:09
Quote Anchor link
hmm... makes sense... je bedoeld dan de knop waarmee de datepicker (DP) wordt aangeroepen? Dan zit ik met het volgende probleem: het formulier wordt dan al gepost voordat er een datum is en later niet meer als er wel een datum is gekozen.

Is er een mogelijkheid om een event te hangen aan het moment waarop DP een datum terug stuurt naar het textveld? Vrees dat mijn (java) kennis hier tekort schiet!

Hieronder de include van de DP class (class.datepicker.php)

Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
<?php

class datePicker
{

    /**
     *  An array of an unlimited number of arrays with three elements.
     *
     *  In these arrays of three elements the first one is the date representing the start of the range (inclusive), the second
     *  one is the date representing the end of the range (inclusive) and the third one represents how days should be skipped
     *  (i.e. "1" means every day in the range should be available for selection, "2" means every second day should be available
     *  for selection and so on)
     *
     *  <i>Note that dates must be represented as UNIX timestamps!</i>
     *
     *  <i>Also note that the range of dates can be anywhere in between 1/1/1970 and 31/12/2038</i>
     *
     *  <code>
     *      /**
     *      *
     *      *   Allow every second day starting from next Monday and up to next Friday
     *      *
     *      {@*}
     *
     *     $dp->selectableDatesRange = array(
     *
     *          array(strtotime("next Monday"), strtotime("next Friday"), 1),
     *
     *     )
     *
     *  </code>
     *
     *  @since 1.0.4
     *
     *  @var array
     */

    var $selectableDatesRange;
    
    /**
     *  An array of an unlimited number of arrays with three elements.
     *
     *  In these arrays of three elements the first one is the year representing the start of the range (inclusive), the second
     *  one is the year representing the end of the range (inclusive) and the third one represents how years should be skipped
     *  (i.e. "1" means every year in the range should be available for selection, "2" means every second year should be available
     *  for selection and so on)
     *
     *  <code>
     *      /**
     *      *
     *      *   Allow every second year starting with 2000 and up to the current year
     *      *   and also, every year from 1990 to 1996
     *      *
     *      {@*}
     *
     *     $dp->selectableYearsRange = array(
     *
     *          array(2000, date("Y"), 2),
     *          array(1990, 1996, 1)
     *
     *     )
     *
     *  </code>
     *
     *  Setting values to this property will make the years show in a select box (rather than static text) enabling the user
     *  to quickly select a year from the given range
     *
     *  @since 1.0.4
     *
     *  @var array
     */

    var $selectableYearsRange;
    
    /**
     *  An array of an unlimited number of arrays with six elements.
     *
     *  In these arrays of six elements the first one is the hour representing the start of the range (inclusive), the second
     *  one is the hour representing the end of the range (exclusive), the third one represents how hours should be skipped
     *  (i.e. "1" means every hour in the range should be available for selection, "2" means every second hour should be available
     *  for selection and so on), the fourth one is the minute representing the start of the range (inclusive), the fifth
     *  one is the minute representing the end of the range (exclusive) and the sixth one represents how minutes should be skipped
     *  (i.e. "15" means every 15th minute in the range should be available for selection, "30" means every 30th minute should be
     *  available for selection and so on),
     *
     *  An unlimited number of ranges can be specified.
     *
     *  Setting this property has sense only if {@link enableTimePicker} property is set to TRUE
     *
     *  <code>
     *      $dp->selectableTimesRange = array(
     *          /**
     *              from hours 10 to 12 and minute 0 to 60 allow every hour and minute
     *          {@*}
     *          array(10, 12, 1, 0, 60, 1),
     *          /**
     *              also, from hours 12 to 18 and minutes 0 to 60 allow only 12, 14 and
     *              16 hours to be selected (through a stepping of 2) and 0, 15, 30, 45
     *              minutes (through a stepping of 15)
     *          {@*}
     *          array(12, 18, 2, 0, 60, 15),
     *      )
     *  </code>
     *
     *  @since 1.0.4
     *
     *  @var array
     */

    var $selectableTimesRange;
    
    /**
     *  If set to TRUE, a button for going to the current month/year will be shown.
     *
     *  Useful when the user can wonder through the years and months and might want to get back.
     *
     *  Default is FALSE
     *
     *  @since 1.0.7
     *
     *  @var boolean
     */

    var $showGoToCurrentMonthYear;
    
    /**
     *  If set to TRUE, a time picker will also be shown
     *
     *  Default is FALSE
     *
     *  @since 1.0.4
     *
     *  @var boolean
     */

    var $enableTimePicker;
    
    /**
     *  Preselects a date in the calendar
     *
     *  <b>The date must be specified as a UNIX timestamp!</b>
     *
     *  @var timestamp
     */

    var $preselectedDate;
    
    /**
     *  Format of the returned day
     *
     *  Any combination allowed by PHP's date() function can be used
     *
     *  <b>Note</b>
     *
     *  <i>You should never use hours, minutes and seconds in your format because you will always have "00:00" appended to your returned
     *  date. If {@link enableTimePicker} is set to TRUE, selected hour and minute will be automatically appended</i>
     *
     *  default was "m d Y"
     *  default is gewijzigd naar "d-m-Y"
     *
     *  @var string
     */

    var $dateFormat;
    
    /**
     *  What day should be taken as the first day of week
     *
     *  Possible values range from 0 (Sunday) to 6 (Saturday)
     *
     *  default was 0 (Sunday)
     *  default is gewijzigd naar 1 (Monday)
     *
     *  @var    integer
     */

    var $firstDayOfWeek;
    
    /**
     *  Height of the calendar window
     *
     *  default is 250
     *
     *  @var integer
     */

    var $windowHeight;

    /**
     *  Width of the calendar window
     *
     *  default is 300
     *
     *  @var integer
     */

    var $windowWidth;

    /**
     *  Language file to use
     *
     *  The name of the php language file you wish to use from the /languages folder.
     *
     *  Without the extension! (i.e. "german" for the german language not "german.php")
     *
     *  default was "english"
     *  default is gewijzigd naar "dutch"
     *
     *  @var   string
     */

    var $language;

    /**
     *  Template folder to use
     *
     *  Note that only the folder of the template you wish to use needs to be specified. Inside the folder
     *  you <b>must</b> have the <b>template.xtpl</b> file which will be automatically loaded
     *
     *  default is "default"
     *
     *  @var   string
     */

    var $template;

    /**
     *  Constructor of the class
     *
     *  @return void
     */

    function datePicker()
    {

    
        // default values to properties
        $this->preselectedDate = "";
        $this->selectableRange = array();
        $this->selectableYearsRange = array();
        $this->selectableTimesRange = array();
        $this->enableTimePicker = false;
        $this->dateFormat = "d-m-Y";
        $this->firstDayOfWeek = 1;
        $this->windowHeight = 300;
        $this->windowWidth = 300;
        $this->language = "dutch";
        $this->template = "default";
        $this->showClearDate = true;
        $this->showGoToCurrentMonthYear = false;

        // get the absolute path of the class. any further includes rely on this
        // and (on a windows machine) replace \ with /

        $this->absolutePath = preg_replace("/\\\/", "/", dirname(__FILE__));

        // remove $_SERVER["DOCUMENT_ROOT"] from the path
        // this path is to be used from within HTML as it is a relative path

        $this->strippedPath = preg_replace("/".preg_replace("/\//", "\/", $_SERVER["DOCUMENT_ROOT"])."/i", "", $this->absolutePath);

    }

    
    /**
     *  Returns the JavaScript code that will open the pop-up window containing the date picker
     *
     *  @param  string  $controlID      the ID of the HTML element (textbox or textarea) where to return the selected value
     *
     *  @param  mixed   $startMonth     (optional) which month to start the calendar from
     *
     *                                  Note that you can also pass a javascript statement as argument!
     *
     *  @param  mixed   $startYear      (optional) which year to start the calendar from
     *
     *                                  Note that you can also pass a javascript statement as argument!
     *
     *  @param  mixed   $startHour      (optional) what hour to show by default
     *
     *                                  Default is "0"
     *
     *                                  This argument will be processed only if the {@link enableTimePicker} property is set to TRUE!
     *
     *                                  Note that you can also pass a javascript statement as argument!
     *
     *  @param  mixed   $startMinute    (optional) what minute to show by default
     *
     *                                  Default is "0"
     *
     *                                  This argument will be processed only if the {@link enableTimePicker} property is set to TRUE!
     *
     *                                  Note that you can also pass a javascript statement as argument!
     *
     *  @return void
     */

    function show($controlID, $startMonth = "", $startYear = "", $startHour = "", $startMinute = "")
    {

    
        // make sure that selectableDatesRange property is ok
        // iterate through all the given ranges

        if (is_array($this->selectableDatesRange) && !empty($this->selectableDatesRange)) {

            foreach ($this->selectableDatesRange as $index=>$range) {

                // a range is valid if it has 3 items
                if (is_array($range) && count($range) == 3) {

                    // iterate through range's items
                    foreach ($range as $key=>$value) {

                        // and make them integers
                        $this->selectableDatesRange[$index][$key] = (int)$this->selectableDatesRange[$index][$key];

                    }


                // if range is erroneous
                } else {

                    unset($this->selectableDatesRange[$index]);

                }

            }


        // if range is erroneous
        } else {

            $this->selectableDatesRange = array();

        }


        // make sure that selectableYearsRange property is ok
        // iterate through all the given ranges

        if (is_array($this->selectableYearsRange) && !empty($this->selectableYearsRange)) {

            foreach ($this->selectableYearsRange as $index=>$range) {

                // a range is valid if it has 3 items
                if (is_array($range) && count($range) == 3) {

                    // iterate through range's items
                    foreach ($range as $key=>$value) {

                        // and make them integers
                        $this->selectableYearsRange[$index][$key] = (int)$this->selectableYearsRange[$index][$key];

                    }


                // if range is erroneous
                } else {

                    unset($this->selectableYearsRange[$index]);
                    
                }

            }


        // if range is erroneous
        } else {

            $this->selectableYearsRange = array();

        }


        // make sure that selectableTimesRange property is ok
        // iterate through all the given ranges

        if (is_array($this->selectableTimesRange) && !empty($this->selectableTimesRange)) {

            foreach ($this->selectableTimesRange as $index=>$range) {

                // a range is valid if it has 6 items
                if (is_array($range) && count($range) == 6) {

                    // iterate through range's items
                    foreach ($range as $key=>$value) {

                        // and make them integers
                        $this->selectableTimesRange[$index][$key] = (int)$this->selectableTimesRange[$index][$key];

                    }


                // if range is erroneous
                } else {

                    unset($this->selectableTimesRange[$index]);

                }

            }

        }
else {

            // if range is erroneous
            $this->selectableTimesRange = array();

        }

        
        return "javascript:var cw = null; cw = window.open('" . $this->strippedPath . "/includes/datepicker.php?preselectedDate=" . $this->preselectedDate . "&selectableDatesRange=" . urlencode(htmlspecialchars(serialize($this->selectableDatesRange), ENT_COMPAT)) . "&selectableYearsRange=" . urlencode(htmlspecialchars(serialize($this->selectableYearsRange), ENT_COMPAT)) . "&selectableTimesRange=" . urlencode(htmlspecialchars(serialize($this->selectableTimesRange), ENT_COMPAT)) . "&enableTimePicker=" . $this->enableTimePicker . "&showGoToCurrentMonthYear=" . ($this->showGoToCurrentMonthYear === TRUE ? 1 : 0) . "&month=" . $startMonth . "&year=" . $startYear . "&hour=" . $startHour . "&minute=" . $startMinute . "&controlName=" . $controlID . "&dateFormat=" . $this->dateFormat . "&firstDayOfWeek=" . $this->firstDayOfWeek . "&language=" . $this->language . "&template=" . $this->template . "','datePicker','width=" . $this->windowWidth . ",height=" . $this->windowHeight . ",left='+(screen.availWidth/2-" . $this->windowWidth/2 . ")+',top='+(screen.availHeight/2-" . $this->windowHeight/2 . ")+',scrollbars=no,toolbar=no,menubar=no,location=no,alwaysraised=yes,modal=yes'); if (window.focus) { cw.focus() } return false";

    }

}


?>
 



Overzicht Reageren

 
 

Om de gebruiksvriendelijkheid van onze website en diensten te optimaliseren maken wij gebruik van cookies. Deze cookies gebruiken wij voor functionaliteiten, analytische gegevens en marketing doeleinden. U vindt meer informatie in onze privacy statement.