Link to home
Start Free TrialLog in
Avatar of nm67304
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("graph").innerHTML = xmlHttp.responseText;
            }
    };
      xmlHttp.open("GET","graphcomp.php?&start=01/01/2010&end=&"+currentdatejf(),true);
      document.getElementById("graph").innerHTML = "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?

Avatar of HainKurt
HainKurt
Flag of Canada image

I could not get what you mean but in this function you can change the values

function selectytd() {
  document.getElementById("txt1").value="Hain";
  document.getElementById("txt2").value="Kurt";
...
SOLUTION
Avatar of HainKurt
HainKurt
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of nm67304
nm67304

ASKER

This looks like it would help
But now I am getting an Error on Page.

what error? on which line?
I did not add anything to cause any error ;)
Avatar of nm67304

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?
Avatar of nm67304

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>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' />
Avatar of nm67304

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' />

Open in new window

Avatar of nm67304

ASKER

Any udpate?
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of nm67304

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