Hi, I have a form, and inside of the form , I have some text fields created by ajax ( the number of text fields is depended on the user''s choice) but when I click on my submit button, rails only send me the data where the components were created normaly. the textfields created by ajax are never put inside of the "params" object. Does anyone know how to get thoses text fields???? Thanks you very much Sayoyo -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Jason Norris
2007-Feb-07 20:11 UTC
Re: how can I get the data from an ajax created textfield
Do all of the text fields have a unique value for name="whatever" ?
I''ve
had problems with my field names not getting created correctly.
Also, do you really need to use AJAX? You could probably just use
client-side javascript for creating blank text fields.
Here is the javascript I use to insert a pair of text fields. I''m not
sure it''s the best way, but it''s woked well so far. The only
requirement
is that you have this:
<input id="counter" type="hidden" value="0"
/> In your page. This is
good, because it allows me to set the value of counter if I''m editing
an
object that already has some of these fields. Then I can start the
generated fields at 12 or 20 or whatever.
Hope this helps!
Jason
Code:
var counter = 0;
function addField()
{
if(counter == 0) {
counter = parseInt(document.getElementById("counter").value);
}
//Get the container Element.
var containerDiv = document.getElementById("fields");
//Set the name for the new input
var inputIdName = "attribute_" + counter;
//Create the DIV
var newInput = document.createElement("div");
//Name the DIV
newInput.setAttribute("id",inputIdName);
//Put the HTML we want into a variable
var insertHTML = ''<table style="margin-left: 30px;"
>\n<tr>'' +
''<td>Name: <input type="text"
name="attribute['' + counter +
'']" size="30" /></td>'' +
''<td>Value: <input name="value['' +
counter + '']" type="text"
size="60"/>'' +
''</td></tr></table>'';
//Put the HTML into our div
newInput.innerHTML = insertHTML;
containerDiv.appendChild(newInput);
//Increment the counter
counter = counter + 1;
}
sayoyo wrote:> Hi,
>
> I have a form, and inside of the form , I have some text fields created
> by ajax ( the number of text fields is depended on the user''s
choice)
> but when I click on my submit button, rails only send me the data where
> the components were created normaly. the textfields created by ajax are
> never put inside of the "params" object.
>
> Does anyone know how to get thoses text fields????
>
> Thanks you very much
>
> Sayoyo
>
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---