0
Good afternoon, I have a function in jQuery to know the number of characters in a given element and needed when more than 300 characters appear the text "see more" and opened the modal with all the information. I happen to know a little bit about jQuery and I don’t even know where to start.
<?php
include('../includes/ligacao.php');
$sql = "SELECT * FROM objetos WHERE numero='AFS1848'";
//executa a query
$result = mysqli_query($conn,$sql);
$array=mysqli_fetch_assoc($result);
$comentarios = $array['comentarios_dados'];
print $comentarios;
?>
<html lang="en">
<head>
<title>Exemplo contagem modal</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<h2>Exemplo contagem modal</h2>
<table>
<tr>
<td>
<?php
echo "<p name='alvo' id='alvo'>".$comentarios."</p>";
?>
<div id="aqui"></div>
</td>
</tr>
</table>
<!-- Modal -->
<div class="modal fade" id="alvoModal" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Modal</h4>
</div>
<div class="modal-body">
<textarea name="alvoTextArea" rows="10" cols="30"></textarea>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Fechar</button>
</div>
</div>
</div>
</div>
</div>
<script type="text/javascript">
$(function() {
// Conta caracteres.
var tamanho = $("#alvo").text().length;
// Exibe um modal com textarea, caso o número de caracteres seja maior que 300.
if ( tamanho > 300 ) {
$("#alvoModal").modal();
}
// Mostra número de caracteres.
$("#aqui").html(tamanho);
});
</script>
</body>
</html>
Good afternoon, Thank you very much for your help. However it will have to be even with a modal or in something "floating" because the text does not fit all where it will be presented.
– Diogo Jesus
That I understood friend, just you do the modal and assign to the click of the button see more to open it. I did not put the modal here because your doubt refers to the count of 300 characters and not how to make a modal.
– Bsalvo
Edited with Modal......
– Bsalvo
I adapted the code to what I need but nothing goes to the modal.
– Diogo Jesus