Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I have used the <code>.val()</code> function on the jQuery host object for each <code>select</code> element to get the initial value of the selected <code>option</code> element. Since you have not specified a <code>value</code> attribute, the initial value of each <code>option</code> element is set to the contents of the element (from the <a href="http://www.w3.org/TR/REC-html40/interact/forms.html#h-17.6" rel="nofollow">HTML 4.01 Spec</a>).</p> <p><strong>JavaScript</strong></p> <pre><code>function getJSONfromTable(tableID) { var res = []; // function now expects an id string passed $('tbody tr', '#' + tableID).each(function() { var $this = $(this); res.push({ 'openH' : parseInt($this.find('#openH').val(), 10), 'openM' : parseInt($this.find('#openM').val(), 10), 'closeH': parseInt($this.find('#closeH').val(), 10), 'closeM': parseInt($this.find('#closeH').val(), 10) }); }); return JSON.stringify(res); } // Example var json = getJSONfromTable('dynTable'); // Returns (example): //=&gt; "[{"openH":1,"openM":3,"closeH":6,"closeM":24}, "openH":4,"openM":2,"closeH":12,"closeM":19}]" </code></pre> <p><strong>A suggestion</strong></p> <p>You may or may not be bothered by this but the duplicate <code>id</code> attributes you're declaring for each set of <code>option</code> elements is invalid according to the <a href="http://www.w3.org/TR/html4/struct/global.html#h-7.5.2" rel="nofollow">HTML spec</a>.</p> <blockquote> <p>(id) This attribute assigns a name to an element. This name must be unique in a document.</p> </blockquote>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload