Ir para conteúdo

POWERED BY:

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

phpbrasil

Gostaria de criar um botao +

Recommended Posts

Pessoal,

E o seguinte...

 

N tela de Cadastro de Livro, tem uma opção em SELECT para escolher um autor do livro. Sendo que o livro pode ter mais de um autor.

 

Gostaria de criar um botao + para que quando o usuario clicasse, aparecesse outro campo select para escolher outro autor.

 

Poderiam me ajudar?

 

 

Obrigada

Compartilhar este post


Link para o post
Compartilhar em outros sites

Olá, tente assim:

<html>
<head>
<?php include('conecta_mysql.php'); ?>
<meta charset="utf-8">
  
  
  <script src="//code.jquery.com/jquery-2.1.0.min.js"></script> <!--Aqui é o JQUERY -->
  <script type="text/javascript">
	$(document).ready(function() {
		$("#autor1_add").click(function(){
			$("#autor2").css('display','inline');
		});
		
		$("#autor2_add").click(function(){
			$("#autor3").css('display','inline');
		});
		
	});
  </script>
  <script language="javascript" type="text/javascript">
  function valida(){
 if(document.fmlr.nomeautor.value ==""){
   alert("Por favor, preencha o campo Nome.");
   document.fmlr.nomeautor.focus();
   return false;
   }else{
   alert("Autor cadastrado com sucesso");
   
   }
  
   
 
 
  }
  </script>
<title> Cadastrar Autor </title>

</head>


<body>
<style>
.autor_add{
  cursor:pointer;
  margin-left:4px;
}

.teste1 input[type=text]{  
border-radius:4px;
-moz-border-radius:4px;
-webkit-border-radius:4px;
box-shadow: 1px 1px 2px #333333; 
-moz-box-shadow: 1px 1px 2px #333333;
-webkit-box-shadow: 1px 1px 2px #333333;
background: #cde5ee; 
border:1px solid #000000;
width:150px;
height:20px;
}
.teste1 input[type=password]{  
border-radius:4px;
-moz-border-radius:4px;
-webkit-border-radius:4px;
box-shadow: 1px 1px 2px #333333; 
-moz-box-shadow: 1px 1px 2px #333333;
-webkit-box-shadow: 1px 1px 2px #333333;
background: #cde5ee; 
border:1px solid #000000;
width:150px;
height:20px;
}
    
    .teste1 textarea{
border: 1px solid #000000;
background:#cccccc;
width:150px;
height:100px;
border-radius:4px;
-moz-border-radius:4px;
-webkit-border-radius:4px;
box-shadow: 1px 1px 2px #333333; 
-moz-box-shadow: 1px 1px 2px #333333;
-webkit-box-shadow: 1px 1px 2px #333333;
}

.teste1  input[type=text]:hover, textarea:hover{ 
         background: #ffffff; border:1px solid #990000;
}

.teste1 input[type=submit]{
        background:#006699;
        color:#ffffff;
}
    .teste1 input[type=reset]{
        background:#006699;
        color:#ffffff;
}
    
    
    
    
    
    
    
    </style>

<form action="insereautor.php" name="fmlr" method="post" target="_myframe" class="teste1" onSubmit="return valida();">


<p style="margin-left:40px"></p>
<br>
<br>
 
    

  
  
  <h1 style="margin-left:40px">Cadastrar Livro</h1>
  <hr width=120% noshade>
  <br>
  
<strong style="margin-left:40px">Código do livro:<font color="red">*</font></strong>  <input type="text" name="nomeautor" size="40" maxlength="40" style="margin-left: 20px;">
<br>
<br>
  <strong style="margin-left:40px">Título:<font color="red">*</font></strong>  <input type="text" name="nomeautor" size="40" maxlength="40" style="margin-left: 20px;">
  
  <br>
  <br>
  <strong style="margin-left:40px">ISBN:</strong>  <input type="text" name="nomeautor" size="40" maxlength="40" style="margin-left: 20px;">
  
  <br>
  <br>
  <div id="autor1"><strong style="margin-left:40px">Autor 1:<font color="red">*</font></strong>  <input type="text" name="nomeautor" size="40" maxlength="40" style="margin-left: 20px;"> <b><span id="autor1_add" class="autor_add" title="Adicionar outro Autor">+</span></b></div>
  
  <br>
  <br>
   <div id="autor2" style="display:none;"><strong style="margin-left:40px">Autor 2:</strong>  <input type="text" name="nomeautor" size="40" maxlength="40" style="margin-left: 20px;"> <b><span id="autor2_add" class="autor_add" title="Adicionar outro Autor">+</span></b> </div>
  
  <br>
  <br>
   <div id="autor3" style="display:none;"><strong style="margin-left:40px">Autor 3:</strong>  <input type="text" name="nomeautor" size="40" maxlength="40" style="margin-left: 20px;"></div>
  
  <br>
  <br>
  <strong style="margin-left:40px">Editora:<font color="red">*</font></strong>  <select name="editora"style="margin-left: 20px;">
  <?php
  $sql = "SELECT nome_editora FROM editora order by nome_editora";
  $resultado = mysql_query($sql) or die (mysql_error());

  while ($registro = mysql_fetch_array($resultado)){
?>
  <option><?=$registro["nome_editora"]?></option>
  <?php

}
mysql_free_result($resultado);
?>
  </select>
  
  
  <br>
  <br>
  <center>
   <br>
  <br>
       <input type="submit" value="Cadastrar">   
       <input type="reset" value="Limpar Dados">
</center>
<form>




</body>

</html>

Espero ter Ajudado ;)

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.