Script...

1

116

I am looking to combine the value of 2 fields. Having trouble getting it to
work. Was looking to also seperate using a '-'.

<script type="text/javascript">
function certno()
{
with (document.forms[0])
{coc_CERTNO.value = (coc_JN.value.concat(coc_CERTIDNO.value));
}
/* Note the extra + operators. */
}
</script>

David
 
1

116

Please disregard below. I found my mistake. I do however have a question
about Date() in Javascript. I am trying to isolate year, month, day, so I
can string together YYMMDD in that order.
 
S

Steve Easton

The following example illustrates the use of the getDate method:

function DateDemo()
{
var d, s = "Today's date is: ";
d = new Date();
s += (d.getMonth() + 1) + "/";
s += d.getDate() + "/";
s += d.getYear();
return(s);
}-- Steve EastonMicrosoft MVP Expression WebFP Cleanerhttp://www.95isalive.com/fixes/fpclean.htmHit Me
FPhttp://www.95isalive.com/fixes/HitMeFP.htm"116 said:
Please disregard below. I found my mistake. I do however have a question
about Date() in Javascript. I am trying to isolate year, month, day, so I
can string together YYMMDD in that order.

116 said:
I am looking to combine the value of 2 fields. Having trouble getting it to
work. Was looking to also seperate using a '-'.

<script type="text/javascript">
function certno()
{
with (document.forms[0])
{coc_CERTNO.value = (coc_JN.value.concat(coc_CERTIDNO.value));
}
/* Note the extra + operators. */
}
</script>

David
 
1

116

Thanks Steve. I am looking to format the year to 'yy' rather than 'yyyy'. I
haven't found anything regarding formatting. Could you point me in the right
direction. Also, getHours(). Can this be formatted to 'HH', or would I have
to have an If...Else to add a zero for <10?

David

Steve Easton said:
The following example illustrates the use of the getDate method:

function DateDemo()
{
var d, s = "Today's date is: ";
d = new Date();
s += (d.getMonth() + 1) + "/";
s += d.getDate() + "/";
s += d.getYear();
return(s);
}-- Steve EastonMicrosoft MVP Expression WebFP Cleanerhttp://www.95isalive.com/fixes/fpclean.htmHit Me
FPhttp://www.95isalive.com/fixes/HitMeFP.htm"116 said:
Please disregard below. I found my mistake. I do however have a question
about Date() in Javascript. I am trying to isolate year, month, day, so I
can string together YYMMDD in that order.

116 said:
I am looking to combine the value of 2 fields. Having trouble getting it to
work. Was looking to also seperate using a '-'.

<script type="text/javascript">
function certno()
{
with (document.forms[0])
{coc_CERTNO.value = (coc_JN.value.concat(coc_CERTIDNO.value));
}
/* Note the extra + operators. */
}
</script>

David


.
 
T

Trevor Lawrence

Hi 116,

1. Try substringing year, i.e.
var yy = d.getYear().toString().substr(2)

2. Use
var hh = d.getHours()
hh = (hh < 10)? '0' + hh : hh;

I don't like year without a century, and the Aussie way is date before
month, but here's the function with date the US way, with hours, months and
dates zero filled, and years without century.

function DateDemo()
{
var d, s = "Today's date is: ";
d = new Date();

var hh = d.getHours()
hh = (hh < 10)? '0' + hh : hh;

var mm = d.getMonth() + 1 ;
mm = (mm < 10)? '0' + mm : mm;

var dd = d.getDate();
dd= (dd < 10)? '0' + dd : dd;

var yy = d.getYear().toString().substr(2)

s += mm + "/";
s += dd + "/";
s += yy + " ";
s += hh + " hours";

document.write(s);
}

The result for me was:
Today's date is: 01/30/10 10 hours

If you prefer, you can return hours minutes and seconds in the format
hh:mm:ss (Post back and I can send the code)
 
1

116

Thanks for the assist Trevor. I am only a few weeks into java, as it might
show. I did however und creating the following, which did give me the
disired string. I plan on studying yours. Much shorter.

<script type="text/javascript">
function certno()
{
with (document.forms[0])
{
var CD = new Date()
var C1 = coc_JN.value
var DASH = "-"
//var DY = CD.getFullYear()
//var DM = CD.getMonth() +1
//var DD = CD.getDate()
var DY = coc_YEAR.value
var DM = coc_MONTH.value
var DD = coc_DATE.value
var TH = CD.getHours()
var TM = CD.getMinutes()

{ DM = +DM + '';
if (DM < 10)
DM = '0' + DM;
else if (DM >= 10)
DM = '' + DM;
}
{ DD = +DD + '';
if (DD < 10)
DD = '0' + DD;
else if (DD >= 10)
DD = '' + DD;
}
{ TH = +TH + '';
if (TH < 10)
TH = '0' + TH;
else if (TH >= 10)
TH = '' + TH;
}
{ TM = +TM + '';
if (TM < 10)
TM = '0' + TM;
else if (TM >= 10)
TM = '' + TM;
}
coc_CERTNO.value = (C1.concat(DASH,DY,DM,DD,DASH,TH,TM));
}
/* Note the extra + operators. */
}
</script>

David
 
T

Trevor Lawrence

David,

It can be even shorter if you use another JavaScript (NOT Java) function to
do the zero fill.

Here is an example with all values (except year) zero filled including
hours, minutes seconds.

function zerofill(n) {
return (n < 10)? '0' + n : n;
}

function DateDemo() {
var d = new Date(), s = "Today's date is: ";
var mm = zerofill(d.getMonth()+1);
var dd = zerofill(d.getDate());
var yy = d.getFullYear().toString().substr(2)

var hh = zerofill(d.getHours());
var min = zerofill(d.getMinutes());
var ss = zerofill(d.getSeconds());

s += mm + "/" + dd + "/" + yy + " "
+ hh + ":" + min + ':' + ss;
document.write(s);
}
This returns
Today's date is: 01/31/10 17:25:20

Of course, you don't have to do it yourself if you accept the standard
format
Use:
var d=new Date();
document.write(d);

This returns
Sun Jan 31 17:25:20 UTC+1100 2010

or you can pull out the bits you want::
var d=new Date().toString();
document.write(d.substr(0,10) + d.substr(28) + d.substr(10,9) )
which returns:
Sun Jan 31 2010 17:25:20

Trevor Lawrence
Canberra
Web Site http://trevorl.mvps.org

116 said:
Thanks for the assist Trevor. I am only a few weeks into java, as it
might
show. I did however und creating the following, which did give me the
disired string. I plan on studying yours. Much shorter.

<script type="text/javascript">
function certno()
{
with (document.forms[0])
{
var CD = new Date()
var C1 = coc_JN.value
var DASH = "-"
//var DY = CD.getFullYear()
//var DM = CD.getMonth() +1
//var DD = CD.getDate()
var DY = coc_YEAR.value
var DM = coc_MONTH.value
var DD = coc_DATE.value
var TH = CD.getHours()
var TM = CD.getMinutes()

{ DM = +DM + '';
if (DM < 10)
DM = '0' + DM;
else if (DM >= 10)
DM = '' + DM;
}
{ DD = +DD + '';
if (DD < 10)
DD = '0' + DD;
else if (DD >= 10)
DD = '' + DD;
}
{ TH = +TH + '';
if (TH < 10)
TH = '0' + TH;
else if (TH >= 10)
TH = '' + TH;
}
{ TM = +TM + '';
if (TM < 10)
TM = '0' + TM;
else if (TM >= 10)
TM = '' + TM;
}
coc_CERTNO.value = (C1.concat(DASH,DY,DM,DD,DASH,TH,TM));
}
/* Note the extra + operators. */
}
</script>

David

Trevor Lawrence said:
Hi 116,

1. Try substringing year, i.e.
var yy = d.getYear().toString().substr(2)

2. Use
var hh = d.getHours()
hh = (hh < 10)? '0' + hh : hh;

I don't like year without a century, and the Aussie way is date before
month, but here's the function with date the US way, with hours, months
and
dates zero filled, and years without century.

function DateDemo()
{
var d, s = "Today's date is: ";
d = new Date();

var hh = d.getHours()
hh = (hh < 10)? '0' + hh : hh;

var mm = d.getMonth() + 1 ;
mm = (mm < 10)? '0' + mm : mm;

var dd = d.getDate();
dd= (dd < 10)? '0' + dd : dd;

var yy = d.getYear().toString().substr(2)

s += mm + "/";
s += dd + "/";
s += yy + " ";
s += hh + " hours";

document.write(s);
}

The result for me was:
Today's date is: 01/30/10 10 hours

If you prefer, you can return hours minutes and seconds in the format
hh:mm:ss (Post back and I can send the code)

--
Trevor Lawrence
Canberra
Web Site http://trevorl.mvps.org




.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

textbox Disable on value.... 2
Dropdown events... 2
DRW Submit Button... 5
Script Question... 4
Function... 15
Checkbox Question... 2
ASK Field Formatting 1
VBA multiple list of values for variable 1

Top