www.tutorialspoint.com Forum Index
Register FAQMemberlistUsergroupsTutorials PointLog in
Reply to topic Page 1 of 1
Prototype Form with Request
Author Message
Reply with quote
Post 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"];
?>

View user's profile Send private message
Display posts from previous:
Reply to topic 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