Forum: Ruby on Rails how can I get the data from an ajax created textfield

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
7efa1e84afccfab2ab6c528afae4d2aa?d=identicon&s=25 sayoyo (Guest)
on 2007-02-07 17:10

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

8b22ad683842861ba91f68d5d32954db?d=identicon&s=25 Jason Norris (Guest)
on 2007-02-07 21:14
(Received via mailing list)
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!


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

    //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"/>' +

    //Put the HTML into our div
    newInput.innerHTML = insertHTML;

    //Increment the counter
    counter = counter + 1;
This topic is locked and can not be replied to.