javascript - how to pass java script value to php in codeigniter -


i have form 2 fields dynamically generated through java script when button clicked.when button clicked each time,the 2 text field generate again , again.now have got count of text field generated in hidden field in javascript.how can value of hiddenfield in controller , insert values of text fields in database,by appending comma in data when text box value entered each time.please me.

my javascript is

<script> var countbox=0; var textbox1=0; var textbox2=0; function getfield() { var newtextbox1="name1"+countbox; var newtextbox2="name2"+countbox; document.getelementbyid('renderdiv').innerhtml+='<br/><input type="text" id="'+newtextbox1+'" name="'+newtextbox1+'" /><br/><input type="text" id="'+newtextbox2+'" name="'+newtextbox2+'" />'; document.getelementbyid('renderdiv').innerhtml+='<br/><input type="hidden" id="hiddentextfield" name="hiddentextfield" value="'+countbox+'" />'; countbox +=1;  } </script> 

my html code is

<input type="button" id="button1" onclick=getfield();/> <div id="renderdiv">     </div> 

inside div 2 textfield generated along hidden field not getting value of textfield in controller while submitting , not getting count of textfield.i tried $hiddenfield=$this->input->post('hiddentextfield');

you have post variable inorder pass server

 <script>     var countbox=0;     var textbox1=0;     var textbox2=0;     function getfield()     {     var newtextbox1="name1"+countbox;     var newtextbox2="name2"+countbox;     document.getelementbyid('renderdiv').innerhtml+='<br/><input type="text" id="'+newtextbox1+'" name="'+newtextbox1+'" /><br/><input type="text" id="'+newtextbox2+'" name="'+newtextbox2+'" />';     document.getelementbyid('renderdiv').innerhtml+='<br/><input type="hidden" id="hiddentextfield" name="hiddentextfield" value="'+countbox+'" />';     countbox +=1;     window.location.href = "index.php?name=" + countbox-1; //change index.php page name      }     </script> 

then in same page

<?php   $hiddenfield=$_get["name"]; ?> 

Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

Function that returns a formatted array in VBA -