473,408 Members | 1,741 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

Automatically insert date in form

Hello all

I have a form, where the user can choose how many delivery days he wants on his order. Lets say he chooses 2 days.

Can i in some way put in a script that automatically sets in the date....?

Ex.
A customer orders something on the 6th of december, and he wants it on a two days service. The date that then should appear as his delivery date is the 8th of december
Dec 5 '07 #1
8 1929
dmjpro
2,476 2GB
Hello all

I have a form, where the user can choose how many delivery days he wants on his order. Lets say he chooses 2 days.

Can i in some way put in a script that automatically sets in the date....?

Ex.
A customer orders something on the 6th of december, and he wants it on a two days service. The date that then should appear as his delivery date is the 8th of december
Yeah it is Possible ..... See the API of Date Object in JavaScript.
Then try some code and come here.
Experts are here to correct your porblem.

Debasis Jana
Dec 5 '07 #2
acoder
16,027 Expert Mod 8TB
Yeah it is Possible ..... See the API of Date Object in JavaScript.
See this reference.

Use the setDate() method and set it to getDate()+2.
Dec 5 '07 #3
I have done the following to get the date:

Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2. function gettheDate() {
  3. Todays = new Date();
  4. TheDate = "" + Todays.getDate() +" / "+ (Todays.getMonth()+ 1) + " / " +
  5. Todays.getYear()
  6. document.form.date.value = TheDate;
  7.  
  8. }
  9. function startdate () {
  10.  
  11.  
  12.     gettheDate()
  13.  
  14. }
  15.  
  16. // end Helpers -->
  17. </script>
Expand|Select|Wrap|Line Numbers
  1. <body topmargin="0" leftmargin="0" onLoad="startdate()">
Expand|Select|Wrap|Line Numbers
  1. <input style="font-size: 11px;" name="date" type="text" size="15" readonly="true">
This works fine. I then have a drop down where the user can choose how many days he wants his order on:

Expand|Select|Wrap|Line Numbers
  1. <select style="width: 140px; font-size: 11px;" name="deliverytime" size="1">
  2.       <option value="0" selected="selected"></option>
  3.       <option value="1">Same day</option>
  4.       <option value="2">2 days</option>
  5.       <option value="3">3 days</option>
  6.     </select>
When the user for example chooses 2 days, the date should automatically change from the current date and two days forward.

Can anyone help with that.....??????
Dec 6 '07 #4
acoder
16,027 Expert Mod 8TB
Add an onchange to the select element:
Expand|Select|Wrap|Line Numbers
  1. <select ... onchange="setDelivery(this.value)">
then set the new date:
Expand|Select|Wrap|Line Numbers
  1. function setDelivery(val) {
  2. delivery = new Date();
  3. delivery.setDate(delivery.getDate() + parseInt(val));
  4. // you have the correct date...
  5. }
Dec 6 '07 #5
Thanks, works great. One thing though. Is it possible for the script to ignore Saturdays and Sundays....? For example an order for two days comes in on a Friday, then the delivery date should be Tuesday.....
Dec 6 '07 #6
acoder
16,027 Expert Mod 8TB
Use getDay() to get the day of the week.
Dec 6 '07 #7
Could you provide with an example of that.........????

Thank you.
Dec 7 '07 #8
acoder
16,027 Expert Mod 8TB
Sunday is 0, Saturday is 6.

So, when you add the days, make sure it doesn't cross or 'land' on these two. If it does, add 2 more.

There are different possibilities and it depends on if you're going to make any changes, e.g. will there be a 4-day option?

One possibility is to add one day at a time until the number of days to be added is reached. If it hits a Saturday (getDay()==6) in between, add 2 immediately. This method would be independent of the number of days to be added.
Dec 7 '07 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Sparrow | last post by:
I have created a table with the following columns... Date(datetime),Actual (Int),Planned (Int) I need to insert weekending dates starting from 23/04/04 looping thru'for the next 52weeks...
8
by: netsurfer | last post by:
Hi: Have a question on making the date automatically filled in by what the user enters in by the date at the top. The date entered at the top would most likely be on a Wednesday then I need...
0
by: neoteny2 | last post by:
I need MS Access to automatically create reports/subreports based on specific criteria. I am building a database in Access 2003 with different locations/sites. I have the "sites" table created...
3
by: Stephen V | last post by:
Can anyone help me out with this problem. I would like to redirect/ go to another php page when my SQL insertion is done and also send a variable at the same time. the idea is, to come on my...
10
by: RoadRunner | last post by:
Hi, I have a employee vacation database that has a vacation table that has the employee name, pay week and date of vacation. I have another lookup table with pay week code and date range for the...
13
by: Mary | last post by:
I'll pulling my hair out on this one and would be so appreciative of any help. I am creating a data entry form to enter results of a student survey. There are 40 questions on the survey. The...
0
BenRatcliffe
by: BenRatcliffe | last post by:
Hi there, I was wondering if anyone could help me. I have a comlpex database with a number of forms that have data entered on them and then saved into the correct table etc. In this instance I am...
0
by: Michael | last post by:
I know I am missing something simple, but I am stuck. When I submit the following for the employee info gets stored in scale1 and scale1 shows the employee number. Can someone show me my...
58
by: bonneylake | last post by:
Hey Everyone, Well recently i been inserting multiple fields for a section in my form called "serial". Well now i am trying to insert multiple fields for the not only the serial section but also...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
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,...
0
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...
0
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.