Hi, I have managed to process the form with help of Prototype''s Ajax function. (Followed guide from here: http://www.ajaxlessons.com/2006/02/11/ajax-workshop-1-ajax-basics-build-a-simple-email-verification-with-prototypejs/) But I am facing difficulties with 2 things: 1. The form does not get submitted when I just press enter in any field (The main submit button''s type is defined as button instead of submit - AJAX script does not work with type submit) 2. On successful completion, I want to set form display as none but I don''t know how to get it working. Following is the part of snnipet from the action page: (PHP) if ($error) { show_error($error); // Show error message exit; } else { show_msg("Word",1); // Success exit; } It shows errror and sucess messages properly but I don''t know how to hide the form while showing sucess message. Following is the javascript code for reference: ------------------------------------------------------------------------------------------------ <script type="text/javascript" language="javascript"> function init () { $(''submit'').onclick = function () { sendData(); } } function sendData () { var url = ''word-action.php''; var pars = Form.serialize(''addword''); var myAjax = new Ajax.Request( url, {method: ''post'', parameters: pars, onLoading: showLoad, onComplete: showResponse} ); } function showLoad () { $(''load'').style.display = ''block''; } function showResponse (originalRequest) { var newData = originalRequest.responseText; $(''load'').style.display = ''none''; $(''status'').innerHTML = newData; } </script> ------------------------------------------------------------------------------------------------ Any kind of help is appriciated. Thanks Deep --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
On Oct 25, 2007, at 2:13 AM, Deep Ganatra wrote:> 1. The form does not get submitted when I just press enter in any > field (The main submit button''s type is defined as button instead of > submit - AJAX script does not work with type submit)Actually, it does. The tutorial does it wrong. (Find a better tutorial.) Instead of observing the submit button''s "click" event, observe the form''s "submit" event. (It also does the assignment poorly, but that''s another issue.) Tying behavior to just the click-- as you observed--makes the form less usable. May I suggest this code instead of the init function (and using the body tag''s onload attribute. Ugh!): Event.observe (window, ''load'', function () { Event.observe(''frm'', ''submit'', sendData); // <-- ''frm'' is the id of the <form> );> 2. On successful completion, I want to set form display as none but I > don''t know how to get it working. Following is the part of snnipet > from the action page: (PHP)If you''re using Prototype, there is no reason to be playing with an element''s style.display attribute. Just show/hide instead. // Not this $(''load'').style.display = ''block''; $(''frm'').style.display = ''none''; // This $(''load'').show(); $(''frm'').hide(); // You may also want to try $(''load'').toggle(); Lastly, since all you''re doing is an HTML update, you may with to look at the Ajax.Updater, which simplifies a bit of what you''re doing here. http://prototypejs.org/api/ajax/updater TAG --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---