SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Zealot
    Join Date
    Jan 2004
    Location
    Manchester
    Posts
    132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Setting value of an input array using jquery

    Hi guys,

    I have an array form input with an id: field[0], field[1] etc.

    How can I set the value of each array element directly?

    $("#field[0]").val("value") doesn't appear to work.

    Many thanks.

  2. #2
    SitePoint Zealot
    Join Date
    Jan 2004
    Location
    Manchester
    Posts
    132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Damn, wrong forum! Sorry about this mods. So used to posting problems on here, I forgot I to change to the correct forum.

  3. #3
    SitePoint Zealot
    Join Date
    Dec 2010
    Posts
    187
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code JavaScript:
    $("#element_id_or_another_selector").eq(0).val("your value");

  4. #4
    SitePoint Zealot
    Join Date
    Jan 2004
    Location
    Manchester
    Posts
    132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by furicane View Post
    Code JavaScript:
    $("#element_id_or_another_selector").eq(0).val("your value");
    Great, thanks for the tip.

    In my example's case, I managed to get it to work by using the following:

    $("[id^=field]").eq(index).val(newvalue);

    Sorry mods again for posting to the wrong forum.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •