|
[x]
Posted via EE Mobile
|
|
| Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again. |
|
|
|
|
Asked by smudgemouse in JavaScript, PHP Scripting Language
Two date fields need to be validated against separate fixed points.
All appears to work well until an out of range date is entered. The alert shows. But then when an allowed date is entered the alert continues.
Is it something to do with the var error_string not clearing?
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:
|
<?php require_once('../Connections/conn_cprof.php'); ?>
<?php
//MX Widgets3 include
require_once('../includes/wdg/WDG.php');
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
mysql_select_db($database_conn_cprof, $conn_cprof);
$query_rst_maxdate = "SELECT DISTINCT max(cp_daysum.daylup) AS max_daylup_1, max(lupcalendar.datemysql) AS max_datemysql_1 FROM (cp_daysum LEFT JOIN lupcalendar ON lupcalendar.id=cp_daysum.daylup) ";
$rst_maxdate = mysql_query($query_rst_maxdate, $conn_cprof) or die(mysql_error());
$row_rst_maxdate = mysql_fetch_assoc($rst_maxdate);
$totalRows_rst_maxdate = mysql_num_rows($rst_maxdate);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:wdg="http://ns.adobe.com/addt">
<head>
<?php
$calstart = strtotime("yesterday");
$calend = strtotime($row_rst_maxdate['max_datemysql_1']);
?>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Test</title>
<script type = "text/javascript">
<!-- hide me from older browsers
function checkMandatory()
{
var error_string = "";
// check the text field
if(<?php echo strtotime($_POST[idstart])?> < <?php echo $calstart ?>)
{
error_string += "Start date must be after today: <?php echo date('F j, Y', strtotime('now'));?>\n";
}
// check the scrollable list
if(<?php echo strtotime($_POST[idend])?> > <?php echo $calend ?>)
{
error_string += "End date must be before <?php echo date('F j, Y',$calend) ?>\n";
}
if (error_string == "")
{
return true;
} else {
error_string = "Date entry needs your attention: \n" + error_string;
alert(error_string);
return false;
}
}
// show me -->
</script>
<script type="text/javascript" src="../includes/common/js/sigslot_core.js"></script>
<script src="../includes/common/js/base.js" type="text/javascript"></script>
<script src="../includes/common/js/utility.js" type="text/javascript"></script>
<script type="text/javascript" src="../includes/wdg/classes/MXWidgets.js"></script>
<script type="text/javascript" src="../includes/wdg/classes/MXWidgets.js.php"></script>
<script type="text/javascript" src="../includes/wdg/classes/Calendar.js"></script>
<script type="text/javascript" src="../includes/wdg/classes/SmartDate.js"></script>
<script type="text/javascript" src="../includes/wdg/calendar/calendar_stripped.js"></script>
<script type="text/javascript" src="../includes/wdg/calendar/calendar-setup_stripped.js"></script>
<script src="../includes/resources/calendar.js"></script>
<script src="" type="text/javascript"></script>
<link href="../includes/skins/mxkollection3.css" rel="stylesheet" type="text/css" media="all" />
<link href="" rel="stylesheet" type="text/css" />
</head>
<body>
<table width="600px" border="0">
<tr>
<td colspan="3"><img src="../graphic09/a4c_cprof_760.jpg" width="760" height="85" /></td>
</tr>
<tr>
<td><?php echo strtotime("now"); ?></td>
<td><?php echo date('F j, Y', strtotime('now'));?></td>
<td>now</td>
</tr>
<tr>
<td width="235"><?php echo strtotime($row_rst_maxdate['max_datemysql_1']); ?></td>
<td width="235"><?php echo date('F j, Y', strtotime($row_rst_maxdate['max_datemysql_1']));?></td>
<td width="521">last date </td>
</tr>
<tr>
<td><?php echo $calstart ?> </td>
<td><?php echo date('F j, Y',$calstart) ?> </td>
<td>calstart is yesterday</td>
</tr>
<tr>
<td><?php echo $calend ?> </td>
<td><?php echo date('F j, Y',$calend) ?> </td>
<td>calend</td>
</tr>
<tr>
<td><?php echo strtotime($_POST[idstart])?> </td>
<td><?php echo $_POST[idstart]?></td>
<td>idstart</td>
</tr>
<tr>
<td><?php echo strtotime($_POST[idend])?> </td>
<td><?php echo $_POST[idend]?></td>
<td>idend</td>
</tr>
<tr>
<td> </td>
<td> </td>
<td bgcolor="#FFFFCC"><form id="form1" name="form1" method="post" action=" " onSubmit = "var the_result = checkMandatory(); return the_result;">
<table width="100%" border="0">
<tr>
<td><label>
<input name="idstart" id="idstart" value="" wdg:mondayfirst="true" wdg:subtype="Calendar" wdg:mask="<?php echo $KT_screen_date_format; ?>" wdg:type="widget" wdg:singleclick="true" wdg:restricttomask="no" wdg:readonly="true" />
</label></td>
</tr>
<tr>
<td><label>
<input name="idend" id="idend" value="" wdg:mondayfirst="true" wdg:subtype="Calendar" wdg:mask="<?php echo $KT_screen_date_format; ?>" wdg:type="widget" wdg:singleclick="true" wdg:restricttomask="no" wdg:readonly="true" />
</label></td>
</tr>
<tr>
<td><label>
<input type="submit" name="button" id="button" value="Submit" />
</label></td>
</tr>
</table>
</form></td>
</tr>
<tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
</table>
</body>
</html>
<?php
mysql_free_result($rst_maxdate);
?>
|
20091111-EE-VQP-92 - Hierarchy / EE_QW_3_20080625