nm67304
asked on
Javascript: Update textfield with button
Good morning. Using PHP and Javascript I am looking to update two text fields with a single button click.
The text fields are a Start and End date
The button is hardcoded for YearToDate information.
Here is my PHP for the button
echo "<input type='button' onclick='selectytd()' value='Select YTD' />";
Here is my Javascript for the function:
function selectytd()
{
var xmlHttp = ajax();
xmlHttp.onreadystatechange =function( )
{
if(xmlHttp.readyState==4)
{
document.getElementById("g raph").inn erHTML = xmlHttp.responseText;
}
};
xmlHttp.open("GET","graphc omp.php?&s tart=01/01 /2010&end= &"+current datejf(),t rue);
document.getElementById("g raph").inn erHTML = "Loading...";
xmlHttp.send(null);
}
function currentdatejf()
{
var currentTime = new Date();
var month = currentTime.getMonth() + 1;
var day = currentTime.getDate();
var year = currentTime.getFullYear();
return month + "/" + day + "/" + year;
}
Could anyone assist with this?
The text fields are a Start and End date
The button is hardcoded for YearToDate information.
Here is my PHP for the button
echo "<input type='button' onclick='selectytd()' value='Select YTD' />";
Here is my Javascript for the function:
function selectytd()
{
var xmlHttp = ajax();
xmlHttp.onreadystatechange
{
if(xmlHttp.readyState==4)
{
document.getElementById("g
}
};
xmlHttp.open("GET","graphc
document.getElementById("g
xmlHttp.send(null);
}
function currentdatejf()
{
var currentTime = new Date();
var month = currentTime.getMonth() + 1;
var day = currentTime.getDate();
var year = currentTime.getFullYear();
return month + "/" + day + "/" + year;
}
Could anyone assist with this?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
This looks like it would help
But now I am getting an Error on Page.
But now I am getting an Error on Page.
what error? on which line?
I did not add anything to cause any error ;)
I did not add anything to cause any error ;)
ASKER
Ok I think if fixed the error but it still doesnt update the two text fields, start and end
"still doesnt update the two text fields, start and end"
I dont see any code for those two text and I dont see how your code will udate those... do you miss any code?
I dont see any code for those two text and I dont see how your code will udate those... do you miss any code?
ASKER
To help you, there are two fields i want the button to update...A Start field and End field, both text fields.
When you click SelectYTD I want it to populate those two text fields with the Start date as 01/01/2010 and the end field with whatever the current date is.
The reason for doing this is because this selectytd button will refresh a portion of the page with information...the date range for that information would pull from whatever is displayed in those two text boxes.
<table><tbody><tr><td>Star t</td><td> <input type='text' id='start' value='<?php echo date("m/d/Y");?>'/></td><t d><a href="javascript:cal1.init ('start',3 60,300);" id="cal1">MM/DD/YYYY</a></ td></tr><t r><td>End< /td><td><i nput type='text' id='end' value='<?php echo date("m/d/Y");?>'/></td><t d><a href="javascript:cal1.init ('end',360 ,300);" id="cal1">MM/DD/YYYY</a></ td></tr></ tbody></ta ble><br/>< input type='button' onclick='refresh()' value='Refresh' />
When you click SelectYTD I want it to populate those two text fields with the Start date as 01/01/2010 and the end field with whatever the current date is.
The reason for doing this is because this selectytd button will refresh a portion of the page with information...the date range for that information would pull from whatever is displayed in those two text boxes.
<table><tbody><tr><td>Star
ASKER
Here is the snippit
<table><tbody><tr><td>Start</td><td><input type='text' id='start' value='<?php echo date("m/d/Y");?>'/></td><td><a href="javascript:cal1.init('start',360,300);" id="cal1">MM/DD/YYYY</a></td></tr><tr><td>End</td><td><input type='text' id='end' value='<?php echo date("m/d/Y");?>'/></td><td><a href="javascript:cal1.init('end',360,300);" id="cal1">MM/DD/YYYY</a></td></tr></tbody></table><br/><input type='button' onclick='refresh()' value='Refresh' />
ASKER
Any udpate?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
That works, thanks.
It answered my posted question.
I posted it because i THOUGHT this would fix my main issue, but it didnt lol. Back to the drawing board.
Thanks though, this cleans it up
It answered my posted question.
I posted it because i THOUGHT this would fix my main issue, but it didnt lol. Back to the drawing board.
Thanks though, this cleans it up
function selectytd() {
document.getElementById("t
document.getElementById("t
...