Prototype DOM-Ajax request

Discussion in 'JavaScript' started by jestep, Jun 5, 2009.

  1. #1
    I'm trying to execute an Ajax request exclusively through a Prototype DOM created form.

    
    var note_form = new Element('div', {className: 'form', style: 'display:none'}).update(
    	new Element('form', {id: 'note_form', method: 'post'}).update(
    		new Element('div', {id: 'form_result', className: 'form_row'}).update(
    			new Element('textarea', {name: 'note', className: 'note'})
    		).insert(
    			new Element('div', {className: 'form_row form_submit', style: 'text-align:center;'}).update(
    				new Element('center').insert(
    					new Element('input', {type: 'submit', value: 'Add note', className: 'submit'})
    				)
    			)
    		)
    	)
    );
    
    Code (markup):
    Now what I would like the submit to do is basically this:

    
    <form onsubmit="new Ajax.Updater('form_result', '/some/url', {asynchronous:true, evalScripts:false, parameters:Form.serialize(this)}); return false;" method="post" />
    
    HTML:
    How can I make the DOM form do the same thing as the HTML form.

    
    function noteSumbit()
    {
    	new Ajax.Updater('form_result', '/some/page', {asynchronous:true, evalScripts:false, parameters:Form.serialize(this)}); 
    	return false;
    }
    
    Event.observe('note_form', 'submit', noteSumbit);
    
    Code (markup):
    Here's where I started, but this causes the page to refresh as if the form was submitted to itself, and not an Ajax request.

    Any help or a tutorial or direction on this would be greatly appreciated.

    Thanks
     
    jestep, Jun 5, 2009 IP