PHP_ Display HTML SELECT information on the page itself

Asked

Viewed 91 times

0

I need a PHP help... as soon as the user clicks on a SELECT option, it is shown on the same page, below the form.

could give me an idea of how to do?

EXAMPLE:

Value 1 Value 2 Value 3

As soon as the user chooses a value appear in the HTML page below and if he continues to choose other values as soon as click the button continue displaying one under the other in the HTML...

  • You have an initial code ?

  • For this you don’t even need to use PHP. You can do it with html and javascript/jQuery. But show what you’ve tried before!

  • You can make a Jquery request, as @Alan quoted would not necessarily require PHP, unless the values to be shown come from a database.

1 answer

0

Below are two options for how to do with jquery.

$('select').change(function() {
  // opção 1
  if ($(this).val()) $('div.op1').append($(this).val() + '<br>');

  // opção 2
  if ($(this).val()) $('div.op2').append($('#html'+$(this).val()).html());
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<select>
  <option value="">Selecione...</option>
  <option value="1">Valor 1</option>
  <option value="2">Valor 2</option>
  <option value="3">Valor 3</option>
</select>
<hr>
<div class="op1"></div>
<hr>
<div style="display:none">
  <div id="html1">Conteúdo HTML 1<br></div>
  <div id="html2">Conteúdo HTML 2<br></div>
  <div id="html3">Conteúdo HTML 3<br></div>
</div>
<div class="op2"></div>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.