1
So, I’m doing a clinic registration form, and on this form is a specialty field that takes the data from another database and shows the list options to choose from, i am trying to put an add button and a remove so that register more than one specialty for each clinic, in the format input=text ta working but the field select I am unable to make it work, nothing happens when clicking.
SCRIPT
$(document).ready(function() {
var campos_max = 10; //max de 10 campos
var x = 1; // campos iniciais
$('#add').click (function(e) {
e.preventDefault(); //prevenir novos clicks
if (x < campos_max) {
$('#listas').append('<div>\
<select name="espc">\
<a href="#" class="remover_campo">Remover</a>\
</div>');
x++;
}
});
// Remover o div anterior
$('#espc').on("click",".remover_campo",function(e) {
e.preventDefault();
$(this).parent('div').remove();
x--;
});
HTML
<p>
<label for="espc">Especialidades</label>
<select name="espc" id="espc">
<?php
include('conectadb.php');
$pesquisa="select codigo_esp,tipo from especialidades order by tipo";
$query=mysqli_query($conn,$pesquisa);
while($dados=mysqli_fetch_array($query))
{
$codigo=$dados['codigo_esp'];
$tipo=$dados['tipo'];
echo "<option value='" .$codigo ."'>" .$tipo ."</option>";
}
?>
</select>
<input type="button" id="add" value="adicionar">
Sorry any silly mistake I’m still novice; Thank you.
In your script you are opening the tag
select
but you’re forgetting to close it– NoobSaibot
is enclosed in the ' >\ '
– Patrick Silva
Negative, to close the tag:
</select>
– NoobSaibot
tried as you said but n changed
– Patrick Silva
This dynamic field you will add will contain the same values of the first correct?
– NoobSaibot
Yes, the idea is that by clicking double the field
– Patrick Silva
I’ll put an answer.
– NoobSaibot
you need to create a database and connect to appear the options to choose, the goal is to duplicate the field to add more in a register
– Patrick Silva