On Apr 24, 4:05 am, katz <[email protected]> wrote:
> Greetings.
> I need to learn how to achieve to dynamically copy form field values
> using Prototype or possibly Ruby.
>
> I want to achieve something like 
> this:http://websitebuildersresource.com/2009/02/05/copy-form-input-data-to...
>
> http://websitebuildersresource.com/demos/jquery-copy-form-data/
>
> Sorry for posting a jQuery example.
> I'm fairly new to Prototype, Scriptaculous and RJS. My goal is to
> achieve similar result using the default libraries of Rails.
> Although I am aware of jQuery noConflict() and and all those techniques
> to make jquery work well with other libraries, I just don't want to use
> it for now.
>
> There aren't too many decent examples on how to copy form values for
> prototype.
>
> My question is:
> How do you use that $F function and form.serialize to copy form field
> values to other fields?
> Also event observers seem to fail to work if defined on head tag. Am I
> right?
>
> http://www.prototypejs.org/api/event/observe
>
> Examples aren't working for me.
>
> So I already have something like this:
> <input id="item_weight"  
> type="text" value="0" size="10" name="item[weight]"/>
>
> <input id="item__copy_weight"  
> type="text" value="0" size="10" name="item[copy_weight]"/>
>
>      <input type="button" id="button3" value="Same as above" />
>
> <script type="text/javascript">
>
>             $('button3').observe('click', function(e) {
>                 var form = Event.findElement(e, 'form');

All form controls have a reference to the form they are in, so:

  var form = this.form;

>
>                 var input = form.down('input[name="item[weight]"]');

Since you now have a reference to the form, the controls are easy:

    form.elements['item[copy_weight]'].value = form.elements['item
[weight]'].value;



--
Rob
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Prototype & script.aculo.us" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to