Saturday, April 20, 2013

Getting data from dynamically created elements.

Here is my view

    <?php
echo " <div id=tables><table  align=center><tr><th colspan=2>Enter Test Details</th></tr>";
?>

<?php
$sec=range(0,20);
echo $this->Form->create('Test', array('enctype' => 'multipart/form-data','id'=>'addtest'));
echo "<tr><td>".$this->Form->input('Name')."</td><td>".$this->Form->input('Price')."</td></tr>";
echo "<tr><td colspan=2>".$this->Form->input('Total_Sections',array('type'=>'select','options'=>$sec,'id'=>'tsec'))."</td></tr>";

?>
<script>
$(document).ready(function ()
{
$("#tsec").change(function() 
{
  var total=$(this).val();
   $(".sectionDiv").remove();
  for(i=1;i<=total;i++)
  {
var htmlstring= '<tr class=sectionDiv><td colspan=2><label for="Section_name_'+i+'">Section  Name</label><input name="data[Test][Section_Name_'+i+'"] id="Section_name_'+i+'" type="text"></td><td><label for="tques_'+i+'">Total  Questions</label><select name="Section_question_'+i+'" id="tques_'+i+'" class="qsel"><option value="1">1</option><option value="2">2</option><option value="3">3</option><option value="4">4</option><option value="5">5</option><option value="6">6</option><option value="7">7</option><option value="8">8</option><option value="9">9</option><option value="10">10</option><option value="11">11</option><option value="12">12</option><option value="13">13</option><option value="14">14</option><option value="15">15</option><option value="16">16</option><option value="17">17</option><option value="18">18</option><option value="19">19</option><option value="20">20</option><option value="21">21</option><option value="22">22</option><option value="23">23</option><option value="24">24</option><option value="25">25</option><option value="26">26</option><option value="27">27</option><option value="28">28</option><option value="29">29</option><option value="30">30</option><option value="31">31</option><option value="32">32</option><option value="33">33</option><option value="34">34</option><option value="35">35</option><option value="36">36</option><option value="37">37</option><option value="38">38</option><option value="39">39</option><option value="40">40</option><option value="41">41</option><option value="42">42</option><option value="43">43</option><option value="44">44</option><option value="45">45</option><option value="46">46</option><option value="47">47</option><option value="48">48</option><option value="49">49</option><option value="50">50</option><option value="51">51</option><option value="52">52</option><option value="53">53</option><option value="54">54</option><option value="55">55</option><option value="56">56</option><option value="57">57</option><option value="58">58</option><option value="59">59</option><option value="60">60</option><option value="61">61</option><option value="62">62</option><option value="63">63</option><option value="64">64</option><option value="65">65</option><option value="66">66</option><option value="67">67</option><option value="68">68</option><option value="69">69</option><option value="70">70</option><option value="71">71</option><option value="72">72</option><option value="73">73</option><option value="74">74</option><option value="75">75</option><option value="76">76</option><option value="77">77</option><option value="78">78</option><option value="79">79</option><option value="80">80</option></select></td></tr>';
$("#tsec").after(htmlstring);
//alert(i);
  }
});
});
</script>
<?php
echo "<tr><td colspan=2>".$this->Form->input('Type')."</td></tr>";
echo "<tr><td colspan=2>".$this->Form->end('Add Test')."</td></tr>";
?>

</table></div>

and here is my controller

    public function index()
{
var_dump($this->data);
print_r($_POST);
}

the output it gives is 

    array (size=1)
  'Test' => 
    array (size=4)
      'Name' => string 'test' (length=4)
      'Price' => string '56' (length=2)
      'Total_Sections' => string '2' (length=1)
      'Type' => string 'ssc' (length=3)
Array ( [_method] => POST [data] => Array ( [Test] => Array ( [Name] => test [Price] => 56 [Total_Sections] => 2 [Type] => ssc ) ) )

but it is not giving data from Dynamically created text filed. I need o resolve this very soon. 

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
 
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

No comments: