Resend my activation email : Register : Log in 
BCF: Bike Chat Forums


Prototype & Ajax Help

Reply to topic
Bike Chat Forums Index -> The Geek Zone
View previous topic : View next topic  
Author Message

Phil.
World Chat Champion



Joined: 02 Feb 2002
Karma :

PostPosted: 13:24 - 03 Apr 2009    Post subject: Prototype & Ajax Help Reply with quote

I picked up some javascript that works with the prototype frame work, i forget where it's from but i expect the changes i need to the code below are pretty simple, I just still dont have much of a clue with JS.

The purpose of this code is to pass form elements to a processing page then send back a confirmation or error message.
Code:

function sendRequest() {
   new Ajax.Request("ajax.subscribe.php",
   {
      method: 'post',
      postBody: 'list_email_add='+ $F('list_email_add'),
      onComplete: showResponse
   });
}

function showResponse(req){
   $('morph').innerHTML= req.responseText;
}


It works fine at the moment, but i need to add a couple more fields to pass, what ever i try doesn't work. Any hints?


Update:

Code above isn't very flexible, but this code:

Code:

<script type="text/javascript" src="prototype.js"></script>
<script type="text/javascript"> 
// <![CDATA[ 
document.observe('dom:loaded', function() {   
    function sendForm(event){ 
        //stop the default submit behaviour 
        Event.stop(event); 
            var oOptions = { 
                method: "POST", 
                parameters: Form.serialize("ajaxForm"), 
                asynchronous: true, 
                onFailure: function (oXHR) { 
                   $('feedback').update(oXHR.statusText); 
                }, 
                onLoading: function (oXHR) { 
                   $('feedback').update('<img src="images/loading.gif" alt="Loading" />'); 
                },                           
                onSuccess: function(oXHR) { 
                   $('feedback').update(oXHR.responseText); 
                }}; 
            var oRequest = new Ajax.Updater({success: oOptions.onSuccess.bindAsEventListener(oOptions)}, "ajax.php", oOptions);             
               } 
               Event.observe('submitButton', 'click', sendForm, false); 
    });   
// ]]> 
</script>


<div id="feedback"> </div> 
<div id="contact"> 
   <form id="ajaxForm"> 
      <input type="text" name="name" /> 
      <input type="submit" id="submitButton" value="send contact form" /> 
     </form> 
</div>


Works pretty well, automatically passes any additonal form elements through post. Hope this comes in handy for someone, one day.
 Back to top
View user's profile Send private message Visit poster's website You must be logged in to rate posts
Old Thread Alert!

The last post was made 17 years, 162 days ago. Instead of replying here, would creating a new thread be more useful?
  Display posts from previous:   
This page may contain affiliate links, which means we may earn a small commission if a visitor clicks through and makes a purchase. By clicking on an affiliate link, you accept that third-party cookies will be set.

Post new topic   Reply to topic    Bike Chat Forums Index -> The Geek Zone All times are GMT + 1 Hour
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
You cannot attach files in this forum
You cannot download files in this forum

Read the Terms of Use! - Powered by phpBB © phpBB Group
 

Debug Mode: ON - Server: birks (www) - Page Generation Time: 0.07 Sec - Server Load: 0.51 - MySQL Queries: 13 - Page Size: 31.98 Kb