0

I have an array of input-fields and via an ajax-call I receive values which I want to put in the array:

<input id="startdateinput[0]" type="text" value="2014-01-01">
<input id="startdateinput[1]" type="text" value="">
<input id="startdateinput[2]" type="text" value="">

The XML looks something like:

    <item key='0'>
      <startdate>2014-01-01</startdate>
    </item>
    <item key='1'>
      <startdate>2014-02-01</startdate>
    </item

I use jQuery something like:

    $(xml).find('item').each(function(){
        startdate=$(this).find('startdate').text();
        key=$(this).attr('key');
        $("#startdate["+key+"]").attr("value",startdate);
    });

Nothing happens....

1 Answer 1

2

You will have to use

$("#startdateinput\\["+key+"\\]").val(startdate);

Your id is starting with startdateinput so need to escape the [ and ], also use .val() to set the value

Demo: Fiddle

Sign up to request clarification or add additional context in comments.

1 Comment

That's real quick and most of all: it works! Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.