Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Submitting JavaScript var - Automatically

Status
Not open for further replies.

X131044

Programmer
Apr 20, 2008
3
I want to grab the client-side date and send it server side automatically without having to use any submit buttons. The routine exists and is working fine except it isn't automatically submitting the date/time. The submit button has to be pressed.

Here is the scenario. Every time an end-user adds a new record I want to grab the date from their machine and put it in to a display field, so that they can see it, and at the same time write that date/time away in PHP to a MySQL table. also not a problem.

I do not have a good understanding of JavaScript can anybody help?

Here is a snippet of coding at the point in question

clientdate=<?=$_REQUEST['Datum']?><br>
<form method="get" action="datetest.php" name="myform">
<!-- The line below sends the datetime upon form submit -->
<input type="hidden" name="clientdate" value="">
<input type="submit" OnClick="document.myform.clientdate.value=Datum;">

 
If you attach an onload event to your page then you can run a function which submits the form automatically when the page loads:

Code:
window.onload = submitForm;

function submitForm() {
   document.forms['myform'].submit();
}

...

<form method="get" action="datetest.php" name="myform">
   <input type="hidden" name="clientdate" value="<?=$_REQUEST['Datum']?>">
</form>

Hope this helps,
Dan




Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Hi Dan,

I am still struggling with the problem. But I have got a little further. I have had a few strange things happen which could well have affected the suggested solution first off, the value="<?=$_REQUEST['Datum']; ?>"> is passes across as literal using LOCALHOST under Windows as the test environment. Running the same thng on my hosted website under Linux nothing is passed across. really puzzling. I have tried and exhausted everything I have researched and still no joy.

Paul
 
Sorry Dan,

Your solution doesn't work

Paul
 
In what way does it not work? Does it not submit the form, or is there another error?

Why not post the [!]client-side[/!] code that you're now having problems with?

Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top