473,718 Members | 1,955 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Two input fields to a single database field

Hello,
I don't know what this would be called, and searches for the subject
above are not useful. FAQ did not seem to provide anything either.
My inherited application already uses Javascript for data input
validations so I thought this would be a good fit for it also.

Here's my situation:
I have a form (below) with a date input to filter with on a single
database field. I need to allow mM/dD/YYYY input (which already
works) and number-of-days-prior -- user's choice. This is supposed to
filter items that have a datestamp n number of days prior to today's
current date OR prior to the date entered. The end criteria for
either is formatted as the date mm/dd/yyyy.

Can Javascript help me with this requirement? What is this called? So
maybe I can search further for existing posts or web pages.

Thanks in advance.

dlrider
form code:
<form name="AdminFind " action="index.c fm?action=admin findlist"
method="post">
Plan modified on/before date:
<input name="plan_main _user_modify_da te" type="text" size=10
maxlength=10 value="">
<input name="find" type="submit" value="Find" onClick="return
validateDate(); " >
</form>

Sep 7 '07 #1
10 1873
Hey dlrider,
See if this is what you are looking for.

<script language="javas cript">
function addtodate(date1 , numberdays)
{
newdate=new Date(date1.getT ime()+numberday s*(1000*60*60*2 4));
return newdate;
}
mydate=addtodat e(new Date(),3);
alert(mydate);
</script>

This should add "numberdays " to the date passed to the function. You
can modify it to subtract as well. You might have to do some
formatting on the mm/dd/yyyy to create the date object to pass to the
function.

Matt R.
On Fri, 07 Sep 2007 12:46:59 -0700, dlrider <tw******@gmail .com>
wrote:
>Hello,
I don't know what this would be called, and searches for the subject
above are not useful. FAQ did not seem to provide anything either.
My inherited application already uses Javascript for data input
validations so I thought this would be a good fit for it also.

Here's my situation:
I have a form (below) with a date input to filter with on a single
database field. I need to allow mM/dD/YYYY input (which already
works) and number-of-days-prior -- user's choice. This is supposed to
filter items that have a datestamp n number of days prior to today's
current date OR prior to the date entered. The end criteria for
either is formatted as the date mm/dd/yyyy.

Can Javascript help me with this requirement? What is this called? So
maybe I can search further for existing posts or web pages.

Thanks in advance.

dlrider
form code:
<form name="AdminFind " action="index.c fm?action=admin findlist"
method="post ">
Plan modified on/before date:
<input name="plan_main _user_modify_da te" type="text" size=10
maxlength=10 value="">
<input name="find" type="submit" value="Find" onClick="return
validateDate() ;" >
</form>
Sep 7 '07 #2
In comp.lang.javas cript message <46************ ***********@new s.orange.f
r>, Sat, 8 Sep 2007 01:44:50, ASM <st************ *********@wanad oo.fr.in
validposted:
>user_day = user_day.split( '/');
probably OK
>user_day = new Date(user_day[2],user_day[1],user_day[0]);
A -1 is usually needed here ............... .^
>// time spent since 1970 for user's day
No, that would mean 86400 seconds for the start of 1971-01-02 local.
You mean "time in milliseconds since 1970-01-01 00:00:00 UTC ..."
>user_day = Date.parse(user _day);
Initially, user_day was a Date Object; Date.parse requires a String, so
implicit conversion is needed; Date.parse will then convert back (and
would get it wrong for most of the First Century AD).
user_day = +user_day // will convert from Date Object to Number,
// reliably and rapidly.
If one has two valid string dates for similar locations and possibly
dissimilar seasons, and the time parts are absent, zero, or similar,
then
DaysDifference = Math.round( ( new Date(DS2)-new Date(DS1) )/864e5 )

--
(c) John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v6.05 IE 6
news:comp.lang. javascript FAQ <URL:http://www.jibbering.c om/faq/index.html>.
<URL:http://www.merlyn.demo n.co.uk/js-index.htmjscr maths, dates, sources.
<URL:http://www.merlyn.demo n.co.uk/TP/BP/Delphi/jscr/&c, FAQ items, links.
Sep 8 '07 #3
In comp.lang.javas cript message <7dc3e394jrrq4e d5a4f54akaokivs 04cce@4ax.
com>, Fri, 7 Sep 2007 16:29:20, Matt Ratliff <ma***@safedata isp.net>
posted:
newdate=new Date(date1.getT ime()+numberday s*(1000*60*60*2 4));
Shoddy coding, but will pass simple-minded testing. OK if used only in
places like Beijing, Accra, Hawaii.

--
(c) John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v6.05 IE 6.
Web <URL:http://www.merlyn.demo n.co.uk/- w. FAQish topics, links, acronyms
PAS EXE etc : <URL:http://www.merlyn.demo n.co.uk/programs/- see 00index.htm
Dates - miscdate.htm moredate.htm js-dates.htm pas-time.htm critdate.htm etc.
Sep 8 '07 #4
ASM
En réponse à Dr J R Stockton qui écrivit, en date du : 8/09/07 22:36,
le message suivant :
In comp.lang.javas cript message <46************ ***********@new s.orange.f
r>, Sat, 8 Sep 2007 01:44:50, ASM <st************ *********@wanad oo.fr.in
validposted:
>user_day = user_day.split( '/');
probably OK
Don't know ... but it works :-)
(didn't try with the part of php code)
>user_day = new Date(user_day[2],user_day[1],user_day[0]);
A -1 is usually needed here ............... .^
oops !?
>// time spent since 1970 for user's day
No, that would mean 86400 seconds for the start of 1971-01-02 local.
You mean "time in milliseconds since 1970-01-01 00:00:00 UTC ..."
OK, thanks for the precision.
>user_day = Date.parse(user _day);
Initially, user_day was a Date Object; Date.parse requires a String, so
implicit conversion is needed;
?? Firefox's Errors consol didn't tell me that was wrong.
I thought that new Date() returned a string, no?
Date.parse will then convert back (and
would get it wrong for most of the First Century AD).
I hope there will be no meeting planed at this time :-)
user_day = +user_day // will convert from Date Object to Number,
// reliably and rapidly.
You're not wrong.
but isn't automatically converted by the condition (day_user>0) ?
If one has two valid string dates for similar locations and possibly
dissimilar seasons, and the time parts are absent, zero, or similar,
then
DaysDifference = Math.round( ( new Date(DS2)-new Date(DS1) )/864e5 )
Great !
Remain only to try to remember it ... !

--
sm
Sep 10 '07 #5
What, and it took you a whole day to come up with this all by
yourself. I guess if everyone had that much time we might be out of
the dark ages by now. :-)

On Sat, 8 Sep 2007 20:42:12 +0100, Dr J R Stockton
<jr*@merlyn.dem on.co.ukwrote:
>In comp.lang.javas cript message <7dc3e394jrrq4e d5a4f54akaokivs 04cce@4ax.
com>, Fri, 7 Sep 2007 16:29:20, Matt Ratliff <ma***@safedata isp.net>
posted:
> newdate=new Date(date1.getT ime()+numberday s*(1000*60*60*2 4));

Shoddy coding, but will pass simple-minded testing. OK if used only in
places like Beijing, Accra, Hawaii.
Sep 10 '07 #6
Thank you all for your responses. However, I am not as intelligent
RE: javascript and could not get these to work. In digging through
the Web for things related I came across this (http://
www.thescripts.com/forum/thread91233.html):

<script type="text/javascript">
function zp(n){
return n<10?("0"+n):n ;
}
function insertDate(t,fo rmat){
var now=new Date();
var DD=zp(now.getDa te());
var MM=zp(now.getMo nth()+1);
var YYYY=now.getFul lYear();
var YY=zp(now.getFu llYear()%100);
format=format.r eplace(/DD/,DD);
format=format.r eplace(/MM/,MM);
format=format.r eplace(/YYYY/,YYYY);
format=format.r eplace(/YY/,YY);
t.value=format;
}
</script>

This would work for our purposes, except I would like it to bump the
month back one by default. I found how to do that but when the
current date is January the month becomes "00". How would I get it to
bump the month to "12" and then the year back one? (I can see now
that I will be more of a plug-n-pray type javascript user). I
envision a nested "if-then" series to do this but I have spun my
wheels doing this before. Thanks again.

D.

Sep 10 '07 #7
In comp.lang.javas cript message <46************ **********@news .orange.fr
>, Mon, 10 Sep 2007 02:23:11, ASM <st************ *********@wanad oo.fr.in
validposted:
>En réponse à Dr J R Stockton qui écrivit, en date du : 8/09/07 22:36,
le message suivant :
>In comp.lang.javas cript message <46************ ***********@new s.orange.f
r>, Sat, 8 Sep 2007 01:44:50, ASM <st************ *********@wanad oo.fr.in
validposted:
>>// time spent since 1970 for user's day
No, that would mean 86400 seconds for the start of 1971-01-02 local.
You mean "time in milliseconds since 1970-01-01 00:00:00 UTC ..."

OK, thanks for the precision.
You do, after all, seem to be of the country in which BIPM and BIH and
IERS reside ... . But many in the obtuser parts of the world ignore the
difference, and suffer, and cause others to suffer too.

>>user_day = Date.parse(user _day);
Initially, user_day was a Date Object; Date.parse requires a String, so
implicit conversion is needed;

?? Firefox's Errors consol didn't tell me that was wrong.
It's valid. It's as valid as going from Paris to Versailles via Monaco.

Another tip for speed : the UTC functions are considerably faster than
the non-UTC ones; only use non-UTC when handling actual date/time,
orneeding to respect time zones or Summer Time.

>I thought that new Date() returned a string, no?
No. It returns a Date Object, which holds an IEEE Double of
milliseconds from epoch and has several Methods. One of those,
toString, is used by default if the context demands a string.
>Date.parse will then convert back (and
would get it wrong for most of the First Century AD).

I hope there will be no meeting planed at this time :-)
But it should be considered when coding for the Date of Easter!
> user_day = +user_day // will convert from Date Object to Number,
// reliably and rapidly.

You're not wrong.
but isn't automatically converted by the condition (day_user>0) ?
It would be; but IIRC it would ALSO be converted elsewhere in the code.

If when assigning to a variable it is the numeric value which matters,
assign a Number. Unary + will do that.

--
(c) John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v6.05 MIME.
Web <URL:http://www.merlyn.demo n.co.uk/- FAQish topics, acronyms, & links.
For news:borland.*, use their server newsgroups.borl and.com ; but first read
Guidelines <URL:http://www.borland.com/newsgroups/guide.htmlff. with care.
Sep 10 '07 #8
In comp.lang.javas cript message <11************ *********@k79g2 000hse.goo
glegroups.com>, Mon, 10 Sep 2007 09:12:54, dlrider <tw******@gmail .com>
posted:
>This would work for our purposes, except I would like it to bump the
month back one by default. I found how to do that but when the
current date is January the month becomes "00". How would I get it to
bump the month to "12" and then the year back one?
When you think you have almost solved that - see below - remember to
consider what should happen if the initial date is May 31st or March
29th.

If permissible, go back 30 days or 4 weeks instead.

It's a good idea to read the newsgroup c.l.j and its FAQ. See below.

--
(c) John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v6.05 IE 6
news:comp.lang. javascript FAQ <URL:http://www.jibbering.c om/faq/index.html>.
<URL:http://www.merlyn.demo n.co.uk/js-index.htmjscr maths, dates, sources.
<URL:http://www.merlyn.demo n.co.uk/TP/BP/Delphi/jscr/&c, FAQ items, links.
Sep 10 '07 #9
ASM
En réponse à Dr J R Stockton qui écrivit, en date du : 10/09/07 21:41,
le message suivant :
In comp.lang.javas cript message <46************ **********@news .orange.fr
>, Mon, 10 Sep 2007 02:23:11, ASM <st************ *********@wanad oo.fr.in
validposted:
>En réponse à Dr J R Stockton qui écrivit, en date du : 8/09/07 22:36,
le message suivant :
>>In comp.lang.javas cript message <46************ ***********@new s.orange.f
r>, Sat, 8 Sep 2007 01:44:50, ASM <st************ *********@wanad oo.fr.in
validposted :
>>Date.parse will then convert back (and
would get it wrong for most of the First Century AD).
I hope there will be no meeting planed at this time :-)

But it should be considered when coding for the Date of Easter!
BIPM and IERS with UTC work on (can give) Date of Easter ?

--
sm
Sep 10 '07 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
17363
by: Rosebud | last post by:
Hello, I'd like some help trying to generate input fields on the fly. What I have on an HTML page is a single text input field labelled #1, e.g. #1 <input type="text">. Next to the field is a button that, on click, I'd like to automatically generate a second text input field below the first, labelled #2. Everytime the button is clicked, another field is created with an incremented label. I explored iframes, but these text fields will...
5
6110
by: ND | last post by:
I need to create a separate field from 4 fields, "street address", "city", "State" and "zip code". For example, Street address - 100 Forest Street City - Seattle State - WA Zip - 05555 Would become:
13
11435
by: Richard Hollenbeck | last post by:
To prevent future apostrophe bugs and errors, isn't it just simpler to forbid an apostrophe from being entered into a text field? For example, couldn't "Alice's Restaurant" be changed to "Alices Restaurant" etc. automatically and programmatically during data entry? This would eliminate my concatinated strings from producing errors when I base the string on a query. Think this is an example of the "Dreaded Apostrophe Bug." If I enter a...
2
14875
by: lgo | last post by:
I have read several variations of this topic posted on this news group. However I was not able to find the answer for my problem. I am trying to build code (see below) to update a large single record using data from a temporary (editing) table with identical field structure. I iterate through the fields (some 50 of them) with a For Each - Next loop to update each field with the SQL statement. The updating works fine with numeric data type...
3
10656
by: google | last post by:
I have a database with four table. In one of the tables, I use about five lookup fields to get populate their dropdown list. I have read that lookup fields are really bad and may cause problems that are hard to find. The main problem I am having right now is that I have a report that is sorted by one of these lookup fields and it only displays the record's ID number. When I add the source table to the query it makes several records...
16
2148
by: Mark A. Sam | last post by:
Hello, I am having a problem with imputting into a string variable: Dim strSQL As String = "INSERT INTO tblContactForm1 (txtName, txtCompany, txtPhone, txtEmail, txtComment, chkGrower, chkProduceDealer, txtOtherCustType, chkStandardBags, chkCustomBags,txtOtherBags) " + _ "VALUES ('" + txtName.Text + "','" + txtCompany.Text + "','" + txtPhone.Text + "','" + txtEmail.Text + "','" + txtComment.Text + "','" +
7
2026
by: Dan | last post by:
(Using Classic ASP & MS Access) I have a page that has 120 fields on it (mostly checkboxes). I cannot split this into smaller pages. So what i want to do is write a class that handles this. in the code it would be something like: Set thisForm = new classBigForm
1
2462
by: Dave | last post by:
I have multiple forms that will create an object. Basically a energy efficiency measure object. The measure object will have a couple of required properties set but after that it can have 10-20 different fields that are optional per measure. How do I account for the different fields that will be posted from the different forms when I create the measure object? Should I create a constructor method with just the required fields as the...
2
1676
by: tbrogdon | last post by:
I have a form to add new employees to tblEmployee with the following fields: Department (text - linked to tblDept - 3 values in a single field) Shift (numeric - linked to tblShift - 3 values in a single field) First Name (tblEmployee.FirstName) LastName (tblEmployee.LastName) Hiring Status (linked to tblHireStatus - 3 values in a single field) Hire Date (Date/Time)
0
8722
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9352
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9206
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9118
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9052
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7985
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5971
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4481
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2550
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.