Hi,
This might be hard to explain, but hopefully I can muddle through and explain what I'm thinking, and someone can either smack me upside the head and tell me it's a bad idea, or point me in the right direction :-)
The page I'm working on has a week's worth of data blocks like this - pseudo code & markup:
<form 1>
field a 1
field b 1
submit 1
response 1
</form 1>
<form 2>
field a 2
field b 2
submit 2
response 2
</form 2>
and so on for either 7 or 14 days.
I'm trying to conceptualize an prototype based js function that can handle all the forms to submit the data to the backend.
What I have now, that works is like the following
Event.observe(window, 'load', ajax_init, false);
function ajax_init () {
Event.observe('form_1', 'submit', send_form_1);
Event.observe('form_2', 'submit', send_form_2);
}
function send_form_1 (e) {
$('response_1').innerHTML = 'doing the deed for 1!';
var myAjax = new Ajax.Updater('response_1', 'ajax_server.php', {method: 'post', parameters: Form.serialize(this)});
Event.stop(e);
}
function send_form_2 (e) {
$('response_2').innerHTML = 'doing the deed for 2!';
var myAjax = new Ajax.Updater('response_2', 'ajax_server.php', {method: 'post', parameters: Form.serialize(this)});
Event.stop(e);
}
But, in my mind, there has to be a way to streamline this so that one function 'send_form' can do the magic rather than having multiple iterations of it. I was looking at the bind functions in prototype, but perhaps it was the late night and lack of coffee, but I wasn't seeing the application of bindAsEventListener in this context.
Thoughts?
Thanks a ton,
Dwayne






Bookmarks