Toon posts:

[js] valideren 2 datumwaarden

Pagina: 1
Acties:
  • 50 views sinds 30-01-2008

Verwijderd

Topicstarter
ik heb 2 datumvelden die gecontroleerd worden als ze gepost worden... Maar hij controleert alleen het eerste datumveld, hoe kan ik ervoor zorgen dat hij ze allebei controleert? Hier een stukkie code...

ik heb b.t.w geen Javascript-errors...

PHP:
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
echo "<script language=\"Javascript\">\n";
            echo "<!--\n";
        echo "function checkForm() {\n";
                
        echo "// Create a var with the original entered date\n";
        
            echo "mydate = this.document.myform.elements['soprichtdatum'].value;\n";
            echo "mydate2 = this.document.myform.elements['svoorwaardedatum'].value;\n";
                
            echo "// Split the original var in year, month and day\n";
            
            echo "parsedate = mydate;\n";
            echo "parsedate2 = mydate2;\n";
            
            echo "firstpos = parsedate.lastIndexOf( \"-\" );\n";
            echo "firstpos2 = parsedate2.lastIndexOf( \"-\" );\n";
            
            echo "lastpos = parsedate.length;\n";
            echo "lastpos2 = parsedate2.length;\n";
            
            echo "myyear = parsedate.substr( firstpos + 1, lastpos );\n";
            echo "myyear2 = parsedate2.substr( firstpos2 + 1, lastpos2 );\n";
            
            echo "parsedate = parsedate.substr( 0, firstpos );\n";
            echo "parsedate2 = parsedate2.substr( 0, firstpos2 );\n";
            
            echo "firstpos = parsedate.lastIndexOf( \"-\" );\n";
            echo "firstpos2 = parsedate2.lastIndexOf( \"-\" );\n";
            
            echo "lastpos = parsedate.length;\n";
            echo "lastpos2 = parsedate2.length;\n";
            
            echo "mymonth = parsedate.substr( firstpos + 1, lastpos );\n";
            echo "mymonth2 = parsedate2.substr( firstpos2 + 1, lastpos2 );\n";
            
            echo "parsedate = parsedate.substr( 0, firstpos );\n";
            echo "parsedate2 = parsedate2.substr( 0, firstpos2 );\n";
            
            echo "firstpos = parsedate.lastIndexOf( \"-\" );\n";
            echo "firstpos2 = parsedate2.lastIndexOf( \"-\" );\n";
            
            echo "lastpos = parsedate.length;\n";
            echo "lastpos2 = parsedate2.length;\n";
            
            echo "myday = parsedate.substr( firstpos + 1, lastpos );\n";
            echo "myday2 = parsedate2.substr( firstpos2 + 1, lastpos2 );\n";
            
            echo "// Make sure day consists of two digits if it has only one\n";
            
            echo "if( myday.match(/^[0-9]{1}$/) != null ) {\n";
            echo "myday = \"0\" + myday;\n";
            echo "}\n";
            
            echo "if( myday2.match(/^[0-9]{1}$/) != null ) {\n";
            echo "myday2 = \"0\" + myday2;\n";
            echo "}\n";
            
            echo "// Make sure month consists of two digits if it has only one\n";
            
            echo "if( mymonth.match(/^[0-9]{1}$/) != null ) {\n";
            echo "mymonth = \"0\" + mymonth;\n";        
            echo "}\n";
            
            echo "if( mymonth2.match(/^[0-9]{1}$/) != null ) {\n";
            echo "mymonth2 = \"0\" + mymonth2;\n";          
            echo "}\n";
                
            echo "// Create the new date to check\n";
            
            echo "checkdate = myday + \"-\" + mymonth + \"-\" + myyear;\n";
            echo "checkdate2 = myday2 + \"-\" + mymonth2 + \"-\" + myyear2;\n";
                
            echo "// Was the original empty?\n";
            
            echo "if( mydate.length == 0 ) {\n";
            echo "alert( \"Oprichting datum mag niet leeg zijn\" );\n";
            echo "return false;\n";
            echo "}\n";         
            
            echo "// Now see if it fits, and day and months are within bounds. If not, bail out and focus on that field\n";
            
            echo "else if( checkdate.match(/^[0-9]{2}-[0-9]{2}-[0-9]{4}$/) == null || myday < 1 || myday > 31 || mymonth < 1 || mymonth > 12 ) {\n";
            echo "alert( \"Oprichting datum niet in geldig dd-mm-yyyy formaat \" );\n";
            echo "this.document.myform.elements['soprichtdatum'].value = checkdate;\n";
            echo "this.document.myform.elements['soprichtdatum'].focus();\n";
            echo "return false;\n";
            echo "}\n";
            
            echo "else {\n";
            echo "this.document.myform.elements['soprichtdatum'].value = checkdate;\n";
            echo "return true;\n";
            echo "}\n";         
            
            echo "if( mydate2.length == 0 ) {\n";
            echo "alert( \"Voorwaarde datum mag niet leeg zijn\" );\n";
            echo "return false;\n";
            echo "}\n";
                        
            echo "else if( checkdate2.match(/^[0-9]{2}-[0-9]{2}-[0-9]{4}$/) == null || myday2 < 1 || myday2 > 31 || mymonth2 < 1 || mymonth2 > 12 ) {\n";
            echo "alert( \"Voorwaarde datum niet in geldig dd-mm-yyyy formaat\" );\n";
            echo "this.document.myform.elements['svoorwaardedatum'].value = checkdate2;\n";
            echo "this.document.myform.elements['svoorwaardedatum'].focus();\n";
            echo "return false;\n";
            echo "}\n";
            
            echo "else {\n";
            echo "this.document.myform.elements['svoorwaardedatum'].value = checkdate2;\n";
            echo "return true;\n";
            echo "}\n";
            
            echo "}\n";
            
            echo "//-->\n";
            echo "</script>\n";

  • Pelle
  • Registratie: Januari 2001
  • Laatst online: 09:36

Pelle

🚴‍♂️

En hier is een slotje. Ga de FAQ maar eens lezen, kijk eens naar je post history en vraag je dan af waarom dit een slotje verdient.

Dit topic is gesloten.