Retrieve values from dynamically added selects using Jquery in PHP -


i wanted chain 3 selects , got working using code. http://jsfiddle.net/fjffj/1/

<div id="filter">             <a id="clone" href="#">+</a> <a id="remove" href="#">-</a>          </div>         <div id="template">             <select class="pais">                 <option value="1">argentina</option>                 <option value="2">chile</option>             </select>             <select class="provincia">                 <option value="1" class="1">san juan</option>                 <option value="2" class="1">mendoza</option>                 <option value="3" class="2">la serena</option>                 <option value="4" class="2">santiago</option>             </select>             <select class="ciudad">                 <option value="1" class="1">rawson</option>                 <option value="2" class="2">godoy cruz</option>                 <option value="3" class="3">coquimbo</option>                 <option value="4" class="4">chiƱihue</option>             </select>         </div> 

the issue have is, how fetch selected values each dropdown in php? example, above creates 3 select boxes when page opened. when click on "+" button , add more rows of selects, how fetch values selects added dynamically?

this did now? still doesnt work.

<?php if(isset($_post['submit'])){     foreach($_post['semester'] $sem){         echo $sem;     } } ?> <!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title>untitled document</title>   <script type='text/javascript' src='http://code.jquery.com/jquery-1.5.js'></script>   <link rel="stylesheet" type="text/css" href="/css/normalize.css">     <link rel="stylesheet" type="text/css" href="/css/result-light.css">          <script type='text/javascript' src="http://www.appelsiini.net/download/jquery.chained.mini.js"></script>     <style type='text/css'>     #template{     display:none; }   </style>    <script type='text/javascript'>//<![cdata[  $(window).load(function(){ $(function() {      // form element cloning     var = 0;     $('#clone').click(function() {          $('#template').clone().appendto('#filter');         $('#filter #template').attr('id', 'duplicate' + i);         $('#filter div:hidden').show();           chainitwithid(i);         i++;     });     $('#remove').click(function() {         $('#filter > div').last().remove();     });      $('#clone').click(); });  function chainitwithid(id) {     $('#duplicate' + id + ' .department').chained('#duplicate' + id + ' .semester');     $('#duplicate' + id + ' .subject').chained('#duplicate' + id + ' .department'); }   function chaintemp() {     $('#template .department').chained('#template .semester');     $('#template .subject').chained('#template .department'); } });//]]>    </script> </head>  <body> <div id="filter">             <a id="clone" href="#">+</a> <a id="remove" href="#">-</a>          </div>         <form name="request" action="<?php $_server['php_self']?>" method="post">         <div id="template">             <select class="semester" name="semester[]">                 <option value="1">1</option>                 <option value="2">2</option>             </select>             <select class="department" name="department[]">                 <option value="eee" class="1">eee</option>                 <option value="ece" class="1">ece</option>                 <option value="mech" class="2">mech</option>                 <option value="cse" class="2">cse</option>             </select>             <select class="subject">                 <option value="1" class="eee ece">s1</option>                 <option value="2" class="ece">s2</option>                 <option value="3" class="mech">s3</option>                 <option value="4" class="cse">s4</option>                                 <option value="5" class="mech">s5</option>                 <option value="6" class="cse eee">s6</option>             </select>         </div>         <input type="submit" name="submit" value="submit" /> </form> </body> </html> 

1) should wrap in tag. use method='post' or method='get' , action='path/to/php_script.php' attributes of

2) should use name attributes selects like

<select name="ciudad" class="ciudad"> 

3) add subbmit button inside 4) after submiting in php_script.php can use $_get['select_name'] or $_post['select_name'] arrays (depend on form method) list selected value


Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -