I have created an app with date range fields.
Here is the javascript used to get current date. ( works fine )
function setCurrDate()
{
var d = new Date();
var currMonth = d.getMonth() + 1;
var currDate = d.getDate();
var currYear = d.getFullYear();
time =
(currMonth < 10 ? "0" : "") + currMonth + "/" +
(currDate < 10 ? "0" : "") + currDate + "/" +
currYear + " " ;
theInput = document.getElementById("EndDate");
theInput.value = time;
}
This is part of the form...
<form>
<INPUT TYPE="text" NAME="EndDate" Size="8" Value="<%=EndDate%>">
</form>
What I need to do is store any updates to the EndDate by the user (if any).
Right now all it's doing is being overwritten during the load or submit of the page because I'm using the <body onload="setCurrDate()"> and it overwrites the EndDate field data.
Any suggestions?
Thanks in advance.
9 1552
Hi swebster, welcome to TSDN!
Do you mean you want to update EndDate in a database?
Hi swebster, welcome to TSDN!
Do you mean you want to update EndDate in a database?
No, I use the EndDate as part of a query string to submit a search query.
So basically, on form load I need the field to equal the current date and if the user updates the date to be something earlier I need to dynamically store the new date in the EndDate variable.
clear as mud? :-)
So how are you going to use this EndDate variable? If it's part of a form, it will get passed to the next page on submit.
Yes, but I can't have the users date over written in EndDate field after the initial results are rendered. Also, I am encoding the string in the URL and the users update to the date field is being captured in the result string but when the form refreshes the current date is placed back in the EndDate field.
I know I am passing the EndDate parameter correctly, so it's just that I need a way to if/else it rather than using the onload option.
I am getting closer... just getting snagged on the syntax.
String EndDate = request.getParameter("EndDate");
if(EndDate == null)
{
EndDate = "" need to set the current date here "" ;
}
This way I would be able to use else and manage the users entry.
It's really more like;
String EndDate = request.getParameter("EndDate");
if(EndDate == null)
{
EndDate = setCurrDate(); // execute js function if EndDate field is null.
}
In that case, set the value with the server code as you already have done and in your onload function, check if EndDate has already been set by checking the input text field.
Yes that is the direction I am leaning towards but none of my syntax is working.
I just tried adding an if statement in the <body tag but that doesn't work.
<body if (EndDate == null) { onload="setCurrDate()" } >
---- or ----
set it in the jsp like this..
String EndDate = request.getParamter("EndDate");
if (EndDate == null )
{ EndDate = setCurrentDate() };
But neither work.
Thanks for all your replies aCoder!
I have successfully added an if statement to the function and it's working now with the onload.
function setCurrDate()
{
if ( queryForm.EndDate.value == '' ) {
var d = new Date();
var currMonth = d.getMonth() + 1;
var currDate = d.getDate();
var currYear = d.getFullYear();
time =
(currMonth < 10 ? "0" : "") + currMonth + "/" +
(currDate < 10 ? "0" : "") + currDate + "/" +
currYear + "" ;
theInput = document.getElementById("EndDate");
theInput.value = time;
}
}
<body onload="setCurrDate()">
Thanks for all your replies aCoder!
I have successfully added an if statement to the function and it's working now with the onload.
No problem, glad you got it working.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Renie83 |
last post by:
Hi I really am going crazy!
I'm using VBScript, ASP, and SQL
My page reminds me of a shopping cart but looking at shopping cart
examples has not helped!
What I have is a page that brings in...
|
by: zlatko |
last post by:
There is a form in an Access Project (.adp, Access front end with SQL
Server) for entering data into a table for temporary storing. Then, by
clicking a botton, several action stored procedures...
|
by: Kevin Lyons |
last post by:
Hello,
I am trying to get my select options (courses) passed correctly from
the following URL: http://www.dslextreme.com/users/kevinlyons/selectBoxes.html
I am having difficulty getting the...
|
by: Kevin Lyons |
last post by:
Hello,
I am trying to get all of my form elements passed correctly from the
following URL:
http://www.dslextreme.com/users/kevinlyons/selectBoxes.html
to the following URL:...
|
by: Bob |
last post by:
I'm new to Access projects and SQL server and am not a veteran VB
programmer. There's a cry for help! I'm attempting to print the
current form on screen by using a command button which the user...
|
by: The KID |
last post by:
Hi All
So I'm new to this. What I am trying to is the user will fill in a series of text boxes or drop downs. Lets say for this instance begin date and end date. Then they would click a button and...
|
by: jmartmem |
last post by:
Greetings,
I have built an Update Record Form in an ASP page. This form contains a number of fields, such as text boxes and menus, to name a few.
Upon clicking the 'submit' button, I want the...
|
by: ToddFur |
last post by:
I see several postings on this but I am still unable to figure out my problem. I can pass the values of my text field but not radio button (or even checkboxes).
My PHP file
<?php
//declare...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
| |