Search Results

Search found 1 results on 1 pages for 'andrewstevens'.

Page 1/1 | 1 

  • jquery to create array from form data

    - by AndrewStevens
    I've been wrestling with this problem for a couple hours now. Essentially, what I need to do is take the following or similar HTML: <div id="excpdivs"> <div class="excpdiv" id="excpdiv0"> Date: <input name="excp[0][date]"> Open: <input name="excp[0][open]"> Close: <input name="excp[0][close]"> </div> <div class="excpdiv" id="expdiv1"> Date: <input name="excp[1][date]"> Open: <input name="excp[1][open]"> Close: <input name="excp[1][close]"> </div> and get an array similar to the following to a php script: Array ( [0] => Array ( [date] => 2012-09-15 [open] => 3:00 [close] => 5:00 ) [1] => Array ( [date] => 2012-09-16 [open] => 2:00 [close] => 5:00 ) ) My main problem is getting the values from the input elements. My latest attempt is the following: var results = []; $(".excpdiv").each(function(){ var item = {}; var inpts = $(this).find("input"); item.date = $(inpts.get(0)).val(); item.open = $(inpts.get(1)).val(); item.close = $(inpts.get(2)).val(); results.push(item); }); Am I on the right track or am I hopelessly lost?

    Read the article

1