bring variables to javascript

0

would like please help me with this problem that I have in javascript, I have a cycle and within that cycle I have a select and I need that every time that the cycle is traversed I can capture the position in which the cycle and the values go of the select and those variables pass them to javascript.

            $i=0;
                while ($row1=mysqli_fetch_array($dato1)) {
                echo $i;
                $i=$i+1;
                echo "
                <form name='form1' id='form1' action='' method'POST'>

                <td><select id='calibre' onchange='ShowSelected();' data-p='".$i."' name='calibre' class='form-control' data-id_memoria='".$row1['id_memoria']."'>
                <option value='0' style='background-color: red'>".$row1['calibre_conductor']."</option>
                <option value='14'>14</option>
                <option value='12'>12</option>
                <option value='10'>10</option>
                <option value='8'>8</option>
                <option value='6'>6</option>
                <option value='4'>4</option>
                <option value='2'>2</option>
                <option value='1/0'>1/0</option>
                <option value='2/0'>2/0</option>
                <option value='4/0'>4/0</option>
                <option value='250'>250</option>
                <option value='350'>350</option>
                <option value='400'>400</option>
                <option value='500'>500</option>
                </select></td>
               }


                <script type="text/javascript">
                function ShowSelected()
               {
               var usercard = document.getElementById("calibre");
               var id = usercard.dataset.p;
               alert(id);

               var cod = document.getElementById("calibre").value;
               alert(cod);


               var combo = document.getElementById("calibre");
               var selected = combo.options[combo.selectedIndex].text;
               alert(selected);
               }

              </script>
    
asked by Daniel rodas garcia 23.04.2018 в 21:54
source

0 answers