Register • FAQ • Memberlist • Usergroups • Tutorials Point • Log in

| Page 1 of 1

Prototype Form with Request
Author | Message
--- | ---
dlarez Joined: 05 Mar 2009 Posts: 1 | Prototype Form with Request 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"];
?>
Thu Mar 05, 2009 1:09 pm |

Display posts from previous: |

| Page 1 of 1

You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum

Powered by phpBB © phpBB Group Design by Vjacheslav Trushkin for phpBBStyles.com