Storing array of data into input with jQuery
<p>Each time the user clicks over a checkbox I add a couple of values to a hidden input value. </p>

<p>Each checkbox stores 2 values and it looks like this:</p>

<pre><code>&lt;input type="checkbox" class="first" value="9598864;3"&gt;
</code></pre>

<p>Where the first value would be: <code>9598864</code> and the second: <code>3</code>.</p>

<p>Currently I am adding data to the input in this way:</p>

<pre><code>var currentValue = $('#myInput').val();
var text;

//adding the value to the input + separator "-"
if($(this).is(':checked')){
    $('#myInput').val(currentValue + "-" + $(this).val());
}

//erasing the value from the input + separator "-"
else{
    text = currentValue .replace("-" + $(this).val(), "");
    $('#myInput').val(text);
}
</code></pre>

<p>The result is something like this:</p>

<pre><code>&lt;input type="hidden" name="demo" value="-9582856;3-9598864;3" id="myInput"&gt;
</code></pre>

<p>Where i get an array of 2 elements each one with another 2 elements inside:</p>

<p><strong>Element 1:</strong></p>

<blockquote>
  <ul>
  <li>9582856</li>
  <li>3</li>
  </ul>
</blockquote>

<p><strong>Element 2:</strong></p>

<blockquote>
  <ul>
  <li>9598864</li>
  <li>3</li>
  </ul>
</blockquote>

<p>What I am doing now is processing the data on the server side (PHP) and exploding those strings by <code>-</code> and <code>;</code> to get the desirable elements. </p>

<p>Is there any other better way to accomplish this task?
Which would be the correct way to store an array of data inside an input using jQuery or Javascript?</p>

<p>Thanks.</p>
