Solved

default date value in input box

Posted on 2010-11-10
9
321 Views
Last Modified: 2012-08-13
Hi,

I have a querie that you can update after putting the date in the input box. Is there a way to put today's date by default in this box, but be able to change the date to a different date to override todays date?

Cheers
<form action="<?php echo $SCRIPT_NAME ?>" method="get">
Date:
<input size="10" type="text" name="today" value=<?PHP echo $today;?>>&nbsp;</input>


<A HREF="#" onClick="cal1x.select(document.forms[0].today,'anchor1x','dd-NNN-yyyy'); return false;" TITLE="Today" NAME="today" ID="anchor1x">
<IMG SRC="images/cal.JPG"></A>

<button value="Update" type="submit">Update</button>
</form>

Open in new window

0
Comment
Question by:Henk_du_Toit
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
9 Comments
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 34105856
Try something like this:

<input size="10" type="text" name="today" value="<?php echo date('r'); ?>" />
0
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 34105866
The ways of handling date and time strings are described in this article.  You may find it helpful.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_201-Handling-date-and-time-in-PHP-and-MySQL.html

Best regards, ~Ray
0
 

Author Comment

by:Henk_du_Toit
ID: 34105978
Hi Ray,

Thanks for your post. I know how to put today's date in by default. The only thing I am having trouble with is overriding when you change it on the web page.

<input size="10" type="text" name="today" value="<?php echo date('d-M-Y'); ?>" />

Doing this brings the default date like I want, but when I change the date to say last week on the web page, the value displayed stays as todays date.
0
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 
LVL 110

Expert Comment

by:Ray Paseur
ID: 34106031
Can you please post a more complete example of your code?  I think I can show you how to use a PHP variable to carry this information to the right places.
0
 

Author Comment

by:Henk_du_Toit
ID: 34106075
Attached is the code for the date and the query that uses the date.

Is this more or less what you wanted?
<SCRIPT LANGUAGE="JavaScript" ID="jscal1x">
     var cal1x = new CalendarPopup("testdiv1");
     cal1x.setCssPrefix("TEST");
     cal1x.showNavigationDropdowns();
     </SCRIPT>
<form action="<?php echo $SCRIPT_NAME ?>" method="get">
Date:
<input size="10" type="text" name="today" value=<?PHP echo $datum;?>>&nbsp;</input>


<A HREF="#" onClick="cal1x.select(document.forms[0].today,'anchor1x','dd-NNN-yyyy'); return false;" TITLE="Today" NAME="today" ID="anchor1x">
<IMG SRC="images/cal.JPG"></A>

<button value="Update" type="submit">Update</button>
</form>

<?php

	$cmdstrnw="select crep,brand,sum(gsales),sum(disc),sum(invsales),sum(pof),subtotalgsales,subtotaldisc,subtotalinvsales,subtotalpof,budget,subtotalbudget,crep1 from
(select a.crep as crep,a.brand as brand,
nvl(e.gsales,0) + nvl(b.gsales,0) + nvl(c.sale,0) as gsales,
nvl(e.disc,0) + nvl(b.disc,0) as disc,
nvl(e.invsales,0) + nvl(b.invsales,0) + nvl(c.sale,0) as invsales,
nvl(e.invsales,0) + nvl(b.invsales,0) + nvl(c.sale,0) - nvl(e.disc,0) - nvl(b.disc,0) - nvl(e.cogs,0) - nvl(b.cogs,0) as pof,
sum(nvl(e.gsales,0) + nvl(b.gsales,0) + nvl(c.sale,0)) over(partition by a.crep) as subtotalgsales,
sum(nvl(e.disc,0) + nvl(b.disc,0)) over(partition by a.crep) as subtotaldisc,
sum(nvl(e.invsales,0) + nvl(b.invsales,0) + nvl(c.sale,0)) over(partition by a.crep) as subtotalinvsales,
sum(nvl(e.invsales,0) + nvl(b.invsales,0) + nvl(c.sale,0) - nvl(e.disc,0) - nvl(b.disc,0) - nvl(e.cogs,0) - nvl(b.cogs,0)) over(partition by a.crep) as subtotalpof,
nvl(d.budget,0) as budget,
sum(nvl(d.budget,0)) over(partition by a.crep) as subtotalbudget,
a.crep1
from
(select a.nama as crep,a.brand as brand1,a.dsca as brand,a.crep as crep1
from brandl a) a
left join
(select crep,brand,sum(gsales) as gsales,sum(disc) as disc,sum(invsales) as invsales,sum(cogs) as cogs from(
    select e.t\$nama as crep,
    case when d.t\$cbrn = 'RETAIL' then d.t\$cbrn else brand.brand end as brand,
    sum(b.t\$damt/b.t\$rats$1) + sum(b.t\$amld/b.t\$rats$1) as gsales,
    sum(b.t\$amld/b.t\$rats$1) as disc,
    sum(b.t\$damt/b.t\$rats$1) as invsales,
    sum(b.t\$copr$1/b.t\$rats$1) as cogs
    from twhinh200099 a, ttdsls401099 b, twhinh220099 c, ttccom110099 d, ttccom001099 e, brand, ttcibd001099 f
    where a.t\$orno = b.t\$orno
    and a.t\$orno = c.t\$orno
    and d.t\$ofbp = a.t\$stco
    and e.t\$emno = d.t\$crep
    and b.t\$pono = c.t\$pono
    and a.t\$oset = c.t\$oset
    and f.t\$item = b.t\$item
    and f.t\$cpcl = brand.cpcl
    and b.t\$dltp <> '1'
    and b.t\$clyn <> '1'
    and d.t\$crep in ('NO','SO','CE','60','CON')
    and to_date(c.t\$addt + 0.54167) between to_date('$startw 00:00:00') and to_date('$today 23:59:59')
   group by e.t\$nama,d.t\$cbrn,brand.brand)
   group by crep,brand) e
on a.crep = e.crep
and a.brand1 = e.brand
left join
    (select crep,brand,sum(gsales) as gsales,sum(disc) as disc,sum(invsales) as invsales,sum(cogs) as cogs from(
    select e.t\$nama as crep,
    case when d.t\$cbrn = 'RETAIL' then d.t\$cbrn else brand.brand end as brand,
    sum(a.t\$damt/a.t\$rats$1) + sum(a.t\$amld/a.t\$rats$1) as gsales,
    sum(a.t\$amld/a.t\$rats$1) as disc,
    sum(a.t\$damt/a.t\$rats$1) as invsales,
    sum(a.t\$copr$1/a.t\$rats$1) as cogs
    from ttdsls401099 a, twhinh210099 b,twhinh200099 c,ttccom110099 d, ttccom001099 e,brand, ttcibd001099 f
    where a.t\$orno = b.t\$orno
    and a.t\$orno = c.t\$orno
    and d.t\$ofbp = c.t\$sfco
    and e.t\$emno = d.t\$crep
    and b.t\$pono = a.t\$pono
    and b.t\$oset = c.t\$oset
    and f.t\$item = a.t\$item
    and f.t\$cpcl = brand.cpcl
    and a.t\$dltp <> '1'
    and a.t\$clyn <> '1'
    and d.t\$crep in ('NO','SO','CE','60','CON')
    and to_date(b.t\$prdt + 0.54167) between to_date('$startw 00:00:00') and to_date('$today 23:59:59')
    group by e.t\$nama,d.t\$cbrn,brand.brand) 
    group by crep, brand) b
on a.crep = b.crep
and a.brand1 = b.brand
left join
  (select crep,brand,sum(sale) as sale from(
  select
	  ttccom001099.t\$nama as crep,
	  case when ttccom110099.t\$cbrn = 'RETAIL' then ttccom110099.t\$cbrn else brand.brand end as brand,
	  sum(tcisli225099.t\$amth$1/tcisli225099.t\$rate$1) as sale
	  from tcisli225099, tcisli220099,ttcibd001099,ttccom100099, ttccom110099, brand, ttccom001099
	  where tcisli225099.t\$item not like '%REBATE%'
	  and tcisli225099.t\$item not like '%PROMO%'
	  and tcisli225099.t\$item not like '%ZZ-1%'
	  and tcisli225099.t\$item not like '%ZZ-5%'
	  and tcisli225099.t\$item not like '%ZZ-6%'
	  and tcisli225099.t\$sfcp = tcisli220099.t\$sfcp
	  and tcisli225099.t\$msid = tcisli220099.t\$msid
	  and tcisli225099.t\$item = ttcibd001099.t\$item
	  and tcisli220099.t\$itbp = ttccom100099.t\$bpid
	  and tcisli220099.t\$ofbp = ttccom110099.t\$ofbp
	  and ttccom001099.t\$emno = ttccom110099.t\$crep
	  and ttcibd001099.t\$cpcl = brand.cpcl
	  and ttccom100099.t\$bpid = ttccom110099.t\$ofbp
	  and ttccom110099.t\$crep in ('NO','SO','CE','60','CON')
    and to_date(tcisli220099.t\$date + 0.54167) between to_date('$startw 00:00:00') and to_date('$today 23:59:59')
	  group by brand.brand,ttccom110099.t\$cbrn,ttccom001099.t\$nama)
    group by crep,brand)c
on c.crep = a.crep
and c.brand = a.brand1
left join
	(select crep,brand,sum(budget) as budget from (
  select b.t\$nama as crep,
    case when a.cata = 'C' then 'Branded' else 'Unbranded' end as brand,
    sum(a.budget) as budget
    from budgets a, ttccom001099 b
    where year = (SELECT CASE
                  WHEN TO_DATE('$startw 23:59:59') BETWEEN TO_DATE('$starty 00:00:00') AND add_months(TO_DATE('$endy 23:59:59'),-3)
                  THEN TO_NUMBER(TO_CHAR(TO_DATE('$startw 23:59:59'),'YYYY'))+ 1
                  ELSE TO_NUMBER(TO_CHAR(TO_DATE('$startw 23:59:59'),'YYYY')) END AS jaar FROM DUAL)
    and a.rep in ('NO','SO','CE','60','CON')
    and a.monnum = (SELECT CASE
                  WHEN TO_DATE('$startw 23:59:59') BETWEEN TO_DATE('$starty 00:00:00') AND add_months(TO_DATE('$endy 23:59:59'),-3)
                  THEN TO_NUMBER(TO_CHAR(TO_DATE('$startw 23:59:59'),'MM'))-3
                  ELSE TO_NUMBER(TO_CHAR(TO_DATE('$startw 23:59:59'),'MM'))+9 END AS jaar FROM DUAL) 
    and a.rep = b.t\$emno
    group by b.t\$nama, a.cata)
    group by crep,brand) d
on d.crep = a.crep
and d.brand = a.brand)
where (gsales <> 0
or budget <> 0)
group by crep,crep1,brand,subtotalgsales,subtotaldisc,subtotalinvsales,subtotalpof,subtotalbudget,budget
order by crep,brand
	";
$parsednw=ociparse($db_conn, $cmdstrnw);
ociexecute ($parsednw);
$nrowsnw=ocifetchstatement($parsednw, $resultsnw);
?>

Open in new window

0
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 34106163
I'm not following this.  In the code you posted, $datum is an undefined variable.  You will get a Notice or a NULL value in the <input> control named "today".

You might also want to put quotes around the string in the value= attribute of the input tag.
0
 

Author Comment

by:Henk_du_Toit
ID: 34106202
Sorry I was playing around with it... $datum should be $today. It works perfectly, the only thing I want to achieve is to bring today's date up by default and be able to change it to any other date with that date being the new value of the input box..
0
 

Accepted Solution

by:
Henk_du_Toit earned 0 total points
ID: 34106442
I have fixed it. Thanks for your help anyway..

Attached is what I did to fix it
global $today;

if (isSet($_GET['today'])) {

$today	= $_GET['today'];
} else {
$today	= date('d-M-Y');
}

Open in new window

0
 

Author Closing Comment

by:Henk_du_Toit
ID: 34134703
I have found a solution myself.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question