Menu
I currently have a form which our clients complete online for design requests for our office. We want the deadline they set to be longer than three days from the current submission day. What I want to be able to do on the form is when they use the drop down boxes to set the deadline date, if it is within three days of the current date, to make a red message under the boxes stating they need to call our office to verify this time frame. How can I do this and would ASP be a better method? Thank you for your help.
-drumbum360
What I want to be able to do on the form is when they use the drop down boxes to set the deadline date, if it is within three days of the current date, to make a red message under the boxes stating they need to call our office to verify this time frame.[/quote]
[code=html]<tr>
<td>Desired Completion date<span style="color:#CC0000">*</span></td>
<td>Month</td><td>Day</td><td>Year</td>
</tr><tr><td></td><td><select name="month">
<option value="1">January</option>
<option value="2">February</option>
<option value="3">March</option>
<option value="4">April</option>
<option value="5">May</option>
<option value="6">June</option>
<option value="7">July</option>
<option value="8">August</option>
<option value="9">September</option>
<option value="10">October</option>
<option value="11">November</option>
<option value="12">December</option>
</select>
</td><td>
<select name="day">
<%
dim i
for i=1 to 31
response.write("<option value='" & i & "'>" & i & "</option>")
next
%>
</select>
</td>
<td><select name="year">
<option value="2009">2009</option>
<option value="2010">2010</option>
</select></td>
</tr>[/code]
How can I do this and would ASP be a better method?[/quote]
[code=html]<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>astupidtitle</title>
<script type="text/javascript">
/***
* getSelectValue function parameters:
* select -object, the actual select passed as an object
* txtBool -boolean, passing true will return the select's text instead of it's value
**
* returns select's selected options value or text if txtBool is true
***/
function getSelectValue(select,txtBool) {
var opt = select.options[select.options.selectedIndex];
return (txtBool) ? opt.text : opt.value;
}
/***
* checkSelectedDate function parameters:
* @form -object containing the other elements
* @yrSel -string, name of year select
* @mthSel -string, name of month select
* @daySel -string, name of day select
* @msgEl -string, id of message element to show error message in
* @daysAllowed -number, number of days to allow
**
* returns true if date is greater than daysAllowed number of days from current time,
* or false and an error message display.
***/
function checkSelectedDate(form,yrSel,mthSel,daySel,msgEl,daysAllowed) {
var now = new Date(),
msgEl = document.getElementById(msgEl),
y = getSelectValue(form[yrSel]),
m = getSelectValue(form[mthSel],true),
d = getSelectValue(form[daySel]),
then = new Date(m + ' ' + d + ',' + y),
diff = then.getTime() - now.getTime(),
errorMsg = "The date selected is less than "+ daysAllowed +" days from now.";
errorMsg += " A minimum of "+ daysAllowed +" days is required please!";
if (diff < (86400000*daysAllowed)) { //86400000 milliseconds per day, 1000 milliseconds = 1 second
msgEl.innerHTML = errorMsg;
return false;
} else {
msgEl.innerHTML = '';
return true;
}
}
</script>
</head>
<body>
<div>
<form name="someForm" action="page2.html" onsubmit="return checkSelectedDate(this,'year','month','day','msgP',3);">
<table>
<tbody>
<tr>
<td>Desired Completion date<span style="color:#CC0000">*</span></td>
<td>Month</td><td>Day</td><td>Year</td>
</tr><tr><td></td><td><select name="month">
<option value="1">January</option>
<option value="2">February</option>
<option value="3">March</option>
<option value="4">April</option>
<option value="5">May</option>
<option value="6">June</option>
<option value="7">July</option>
<option value="8">August</option>
<option value="9">September</option>
<option value="10">October</option>
<option value="11">November</option>
<option value="12">December</option>
</select>
</td><td>
<select name="day">
<!-- remove the below script block entirely, I just used it to mimic your asp or whatever that is below, to print out the day select's options -->
<script type="text/javascript">
for (var i = 1; i < 32; i++) {
document.write('<option value="'+i+'">'+i+'</option>');
}
</script>
<%
dim i
for i=1 to 31
response.write("<option value='" & i & "'>" & i & "</option>")
next
%>
</select>
</td>
<td><select name="year">
<option value="2009">2009</option>
<option value="2010">2010</option>
</select></td>
<td><input type="submit" value="Submit"></td>
</tr>
</tbody>
</table>
</form>
<p id="msgP" style="color:red;"> </p>
</div>
</body>
</html>[/code]
[code=html]<script type="text/javascript">
function checkform(f)
{
if (f.requester.value=='') // not empty
{
// Name is wrong
alert('You must enter a name');
return false;
}
else if (!/(^d+$)/.test(f.phone.value)) // numbers only
{
// phone # is wrong
alert('You must enter a valid phone number')
return false;
}
else if (f.email.value.indexOf("@")==-1) // contains '@'
{
// email is wrong
alert('You must enter a valid email address')
return false;
}
else if (f.completion.value=='') // not empty
{
// Completion date is missing
alert('You must enter a completion date');
return false;
}
else if (f.meet.value=='') //not empty
{
//When I can meet is missing
alert('Please enter a time you can meet')
return false;
}
else if (f.projectTitle.value=='') // not empty
{
// something is wrong
alert('You must enter a project title');
return false;
}
else if (f.audience.value=='') // not empty
{
// something is wrong
alert('You must enter an audience');
return false;
}
else if (f.vision.value=='') // not empty<br />
{
// something is wrong
alert('You must explain your vision to us');
return false;
}
// If the script gets this far through all of your fields
// without problems, it's ok and you can submit the form
return true;
}
/***
* getSelectValue function parameters:
* select -object, the actual select passed as an object
* txtBool -boolean, passing true will return the select's text instead of it's value
**
* returns select's selected options value or text if txtBool is true
***/
function getSelectValue(select,txtBool) {
var opt = select.options[select.options.selectedIndex];
return (txtBool) ? opt.text : opt.value;
}
/***
* checkSelectedDate function parameters:
* @form -object containing the other elements
* @yrSel -string, name of year select
* @mthSel -string, name of month select
* @daySel -string, name of day select
* @msgEl -string, id of message element to show error message in
* @daysAllowed -number, number of days to allow
**
* returns true if date is greater than daysAllowed number of days from current time,
* or false and an error message display.
***/
function checkSelectedDate(form,yrSel,mthSel,daySel,msgEl,daysAllowed) {
var now = new Date(),
msgEl = document.getElementById(msgEl),
y = getSelectValue(form[yrSel]),
m = getSelectValue(form[mthSel],true),
d = getSelectValue(form[daySel]),
then = new Date(m + ' ' + d + ',' + y),
diff = then.getTime() - now.getTime(),
errorMsg = "The date selected is less than "+ daysAllowed +" days from now.";
errorMsg += " A minimum of "+ daysAllowed +" days is required please!";
if (diff < (86400000*daysAllowed)) { //86400000 milliseconds per day, 1000 milliseconds = 1 second
msgEl.innerHTML = errorMsg;
return false;
} else {
msgEl.innerHTML = '';
return true;
}
}
</script>
</head>
<body>
<div id="container">
<div id="title">
<p>Request Form</p><p> <b style="color:#FF0000">If you submitted a project request between April 9th - April 15th via this form and got an error email in your inbox then Housing Design DID NOT recieve the request due to a technical error. Please re-submit the request and we will get back to you asap.</b></p>
</div>
<div id="line">
</div>
<div id="content">
<form action="processForm.asp" method="post" onSubmit="return checkSelectedDate(this,'year','month','day','msgP',3);">
<div id="left"><br />
<h4>Who are you?</h4>
<table>
<tr>
<td>Name<span style="color:#CC0000">*</span></td>
<td colspan="3"><input name="requester" type="text" id="requester" value="" /></td>
</tr>
<tr>
<td>Department<span style="color:#CC0000">*</span></td>
<td colspan="3"><select name="department">
<option value="housing">Housing</option>
<option value="conseling center">Counseling Center</option>
<option value="health services">Health Services</option>
<option value="other">Other</option>
</select>
</td>
</tr>
<tr>
<td>Phone<span style="color:#CC0000">*</span></td>
<td colspan="3"><input name="phone" type="text" id="phone" value="" /></td>
</tr>
<tr>
<td>Email<span style="color:#CC0000">*</span></td>
<td colspan="3"><input name="email" type="text" id="email" value="" /></td>
</tr>
<tr>
<td>Desired Completion date<span style="color:#CC0000">*</span></td>
<td>Month</td><td>Day</td><td>Year</td>
</tr><tr><td></td><td><select name="month">
<option value="1">January</option>
<option value="2">February</option>
<option value="3">March</option>
<option value="4">April</option>
<option value="5">May</option>
<option value="6">June</option>
<option value="7">July</option>
<option value="8">August</option>
<option value="9">September</option>
<option value="10">October</option>
<option value="11">November</option>
<option value="12">December</option>
</select>
</td><td>
<select name="day">
<%
dim i
for i=1 to 31
response.write("<option value='" & i & "'>" & i & "</option>")
next
%>
</select>
</td>
<td><select name="year">
<option value="2009">2009</option>
<option value="2010">2010</option>
</select></td>
</tr>
<tr><td><p id="msgP" style="color:red;">Please Call our office as your due date is short </p></td></tr>
<tr>
<td>Times you can meet<span style="color:#CC0000">*</span></td>
<td colspan="3"><input name="meet" type="text" id="meet" value="" /></td>
</tr>
</table>
[/code]
I would like it to appear right away ..... not upon submitting the form[/quote]
[code=html]<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>some title</title>
<style type="text/css">
#msgP { display:none; color:red; margin:0; }
</style>
<script type="text/javascript">
/*<![CDATA[*/ /*>fool my syntax hi-liter*/
function checkform(f) {
var errStr = '';
var enoughTime = checkSelectedDate(f,'year','month','day','msgP',3); //true/false
if (f.requester.value=='') {
errStr += "You must enter a namen";
}
if(!/(^d+$)/.test(f.phone.value)) {
errStr += "You must enter a valid phone numbern";
}
if (f.email.value.indexOf("@")==-1) {
errStr += "You must enter a valid email addressn";
}
/***** begin comment out, f.completion not in form
*I assume this part could be removed, replacing f.completion with the selects?*
if (f.completion.value=='') {
errStr += "You must enter a completion daten";
}
end comment out*****/
if (f.meet.value=='') {
errStr += "Please enter a time you can meetn";
}
/***** commenting out for testing, items 'projectTitle', 'audience' & 'vision' not in form
if (f.projectTitle.value=='') {
errStr += "You must enter a project titlen";
}
if (f.audience.value=='') {
errStr += "You must enter an audiencen";
}
if (f.vision.value=='') {
errStr += "You must explain your vision to usn";
}
end comment out*****/
if (errStr.length > 0) {
alert(errStr);
return false;
}
return enoughTime;
}
/***
* getSelectValue function parameters:
* @select -object, the actual select passed as an object
* @txtBool -boolean, passing true will return the select's text instead of it's value
**
* returns select's selected options value or text if txtBool is true
***/
function getSelectValue(select,txtBool) {
var opt = select.options[select.options.selectedIndex];
return (txtBool) ? opt.text : opt.value;
}
/***
* checkSelectedDate function parameters:
* @form -object containing the other elements
* @yrSel -string, name of year select
* @mthSel -string, name of month select
* @daySel -string, name of day select
* @msgEl -string, id of message element to un-hide which contains your error message
* @daysAllowed -number, number of days to allow
**
* returns true if date is greater than daysAllowed number of days from current time,
* or false and an error message display.
***/
function checkSelectedDate(form,yrSel,mthSel,daySel,msgEl,daysAllowed) {
var now = new Date(),
msgEl = document.getElementById(msgEl),
y = getSelectValue(form[yrSel]),
m = getSelectValue(form[mthSel],true),
d = getSelectValue(form[daySel]),
then = new Date(m + ' ' + d + ',' + y),
diff = then.getTime() - now.getTime();
if (diff < (86400000*daysAllowed)) { //86400000 milliseconds per day, 1000 milliseconds = 1 second
msgEl.style.display = "block";
return false;
} else {
msgEl.style.display = "none";
return true;
}
}
window.onload = function () {
//will set the date selects to the earliest completion date available
//note allowedDays variable below should be 1 greater than
//the daysAllowed argument passed in to the checkSelectedDate function.
//Also sets the form's onsubmit handler, instead of having it in-line in the html
var form = document.requestForm,
ySel = form.year,
mSel = form.month,
dSel = form.day,
d = new Date(),
oy = d.getFullYear(),
allowedDays = 4; //adjust this if desired
form.reset();
d.setTime(d.getTime() + (86400000*allowedDays)); //86400000 milliseconds in a day
var y = d.getFullYear();
var m = d.getMonth();
var day = d.getDate();
if (y > oy) { //this will only occur a couple days at end of year, but oh well, it's neet. And..
//I am presuming that your server side code would be set up to display only two years
//in the year select, with current year being first option and current year plus 1 as second option.
//If you want to TEST how this works: in the above variable declaration when it says d = new Date()
//enter a date in the parens of the Date in the following format:Example: d = new Date("Dec 28, 2009")
//and then you will note the 2009 option is no longer available
ySel.remove(0); //removes the first option in the year select
}
mSel.selectedIndex = m; //no need to subtract here, values returned by getMonth() start at 0 for the months
dSel.selectedIndex = day - 1; //subtracting 1 because the values in select start numbered at 1, and indexes start at 0
form.onsubmit = function () {
return checkform(this);
};
};
/*]]>*/
</script>
</head>
<body>
<div id="container">
<div id="title">
<p>Request Form</p><p> <b style="color:#FF0000">If you submitted a project request between April 9th - April 15th via this form and got an error email in your inbox then Housing Design DID NOT recieve the request due to a technical error. Please re-submit the request and we will get back to you asap.</b></p>
</div>
<div id="line">
</div>
<div id="content">
<form name="requestForm" action="page2.html" method="post">
<div id="left"><br />
<h4>Who are you?</h4>
<table>
<tr>
<td>Name<span style="color:#CC0000">*</span></td>
<td colspan="3"><input name="requester" type="text" id="requester" value="" /></td>
</tr>
<tr>
<td>Department<span style="color:#CC0000">*</span></td>
<td colspan="3"><select name="department">
<option value="housing">Housing</option>
<option value="conseling center">Counseling Center</option>
<option value="health services">Health Services</option>
<option value="other">Other</option>
</select>
</td>
</tr>
<tr>
<td>Phone<span style="color:#CC0000">*</span></td>
<td colspan="3"><input name="phone" type="text" id="phone" value="" /></td>
</tr>
<tr>
<td>Email<span style="color:#CC0000">*</span></td>
<td colspan="3"><input name="email" type="text" id="email" value="" /></td>
</tr>
<tr>
<td>Desired Completion date<span style="color:#CC0000">*</span></td>
<td>Month</td><td>Day</td><td>Year</td>
</tr><tr><td></td><td><select name="month">
<option value="1">January</option>
<option value="2">February</option>
<option value="3">March</option>
<option value="4">April</option>
<option value="5">May</option>
<option value="6">June</option>
<option value="7">July</option>
<option value="8">August</option>
<option value="9">September</option>
<option value="10">October</option>
<option value="11">November</option>
<option value="12">December</option>
</select>
</td><td>
<select name="day">
<!-- remove the below script block entirely, I just used it to mimic your asp or whatever that is below, to print out the day select's options -->
<script type="text/javascript">
/*<![CDATA[*/ /*>fool my syntax hi-liter*/
for (var i = 1; i < 32; i++) {
document.write('<option value="'+i+'">'+i+'</option>');
}
/*]]>*/
</script>
<!--<%
dim i
for i=1 to 31
response.write("<option value='" & i & "'>" & i & "</option>")
next
%>-->
</select>
</td>
<td><select name="year">
<option value="2009">2009</option>
<option value="2010">2010</option>
</select></td>
</tr>
<tr><td colspan="3"><p id="msgP">Please Call our office as your due date is short</p></td></tr>
<tr>
<td>Times you can meet<span style="color:#CC0000">*</span></td>
<td colspan="3"><input name="meet" type="text" id="meet" value="" /></td>
</tr>
<tr><td><input type="submit" value="Submit" /></td></tr>
</table>
</div><!-- END LEFT DIV -->
</form>
</div><!-- END CONTENT DIV -->
</div><!-- END CONTAINER DIV -->
</body>
</html>[/code]
0.1.9 — BETA 5.29