Note that there are some explanatory texts on larger screens.

plurals
  1. POGet the data that is being loaded by jquery in PHP CodeIgniter
    primarykey
    data
    text
    <p>I have this dropdown menu using <code>form_helper</code> in CodeIgniter:</p> <pre><code> &lt;?php if($materialType): ?&gt; &lt;?php $material_options = array(); foreach($materialType as $rows){ $material_options[$rows-&gt;id] = $rows-&gt;category; } echo form_dropdown('materialType',$material_options,'','id="materialType"'); ?&gt; &lt;?php endif; ?&gt; &lt;div id="materials"&gt;&lt;/div&gt; </code></pre> <p>The code above is inside a <code>&lt;form&gt;</code> tag and I have this script:</p> <pre><code> &lt;script type="text/javascript"&gt; var base_url = "&lt;?php echo base_url(); ?&gt;"; &lt;/script&gt; &lt;script&gt; $(document).ready(function(){ $(document).on('change','#materialType',function(){ loadthis(); }); function loadthis(){ var ID = $('#materialType').val(); var dataString = 'id='+ ID ; $.ajax({ type: "POST", url: base_url + "index.php/admin/get_material", data: dataString, cache: false, success: function(data) { $('#materials').html(data); } }); } loadthis(); }); &lt;/script&gt; </code></pre> <p>And here is the code that is being loaded:</p> <pre><code> &lt;div id="materials"&gt; &lt;?php if($materials): ?&gt; &lt;table&gt; &lt;th&gt;Name&lt;/th&gt; &lt;th&gt;Description&lt;/th&gt; &lt;?php foreach($materials as $row): ?&gt; &lt;tr&gt; &lt;td&gt;&lt;?php echo $row-&gt;mname; ?&gt;&lt;/td&gt; &lt;td&gt;&lt;?php echo $row-&gt;mdesc; ?&gt;&lt;/td&gt; &lt;td&gt; &lt;button class="try" value="&lt;?php echo $row-&gt;id; ?&gt;"&gt;Add&lt;/button&gt; &lt;/td&gt; &lt;/tr&gt; &lt;?php endforeach; ?&gt; &lt;/table&gt; &lt;?php else: ?&gt; &lt;div class="alert alert-error" style="width:300px;"&gt;No Resource Available!&lt;/div&gt; &lt;?php endif; ?&gt; </code></pre> <p> <pre><code> $(document).on('click','.try',function(){ alert($(this).val()); return false; }); </code></pre> <p>And what i want is if the <code>Add</code> <code>button</code> is being click I can get the <code>ID</code>,<code>mname</code> and store it until the form is submitted.<br /> How can I do that using <code>.data()</code> in jquery? or Any ideas on how to store it until the form is being submit.</p>
    singulars
    1. This table or related slice is empty.
    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.
 

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