I´m working with the following code to process a form without refreshing the page and showing a message. That i´m still working on. since I have 2 forms in the html, i´d like to know how to send the form name as a parameter to trigger the function, and to process the datafields from each form (separately of course).
HTML FILE:
<html>
<head>
<script>
<!-- For dissapearing message working with DW´s Effects
function timedMsg()
{
var t1=setTimeout("MM_effectAppearFade('show', 1000, 100, 0, false)",4000);
}
function MM_effectAppearFade(targetElement, duration, from, to, toggle)
{
Spry.Effect.DoFade(targetElement, {duration: duration, from: from, to: to, toggle: toggle});
}
//-->
</script>
<script>
<!-- For processing the request
function sendRequest() {
new Ajax.Request("save.php",
{
method: 'post',
postBody: 'field1='+ $F('field1'),
onComplete: showResponse
});
}
function showResponse(req){
$('show').innerHTML= req.responseText;
MM_effectAppearFade('show', 1000, 0, 100, false);
timedMsg();
}
</script>
<script type="text/javascript" src="../js/prototype.js"></script>
<script src="../SpryAssets/SpryEffects.js" type="text/javascript"></script>
<body>
<form id="test" onSubmit="return false;">
<input type="text" name="field1" id="field1" >
<input type="submit" value="submit" onClick="sendRequest()">
</form>
<form id="test2" onSubmit="return false;">
<input type="text" name="field1" id="field1" >
<input type="submit" value="submit" onClick="sendRequest()">
</form>
<div id="show"></div>
</body>
</html>
------------------
PHP FILE ('save.php')
<?php
if($_POST["field1"] == "")
echo "name is empty";
else
echo "you typed ".$_POST["field1"];
?>