Tuesday, August 7, 2007

How to auto-submit a form

Sometimes it's useful to pass data to a hidden page that processes the data then passes the new data to another page. To pass the data through forms, use javascript. Set a body onload function with $("form_name").submit() to submit the form when the page finishes loading.


....data processing code here
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"\n
<html xmlns="http://www.w3.org/1999/xhtml">
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<script type="text/javascript" src="javascripts/prototype.js"></script>
<body onload="$('newdata').submit()">
<form id="newdata" name="newdata" method="post" action="newviewer.php">
<input type="hidden" id="data1" name="data1" value="x1">


Eugene said...

Thanks! Just what I needed.

Eric Schoeller said...

hehe this makes no sense to me where is prototype.js !!!??