Using SELECT to list information

Asked

Viewed 93 times

3

I need a little help for a situation. I need to list information within the states. EX: If I click on Acre, I need to click on a box with some information about it. But I don’t know how to make this information appear. I don’t want to use php or java, because it will be little information.

Can I only do this with html? Is there a website that explains? I did a search and I couldn’t find it.. If someone helps me, I appreciate it.! :)

    <label class="estados">Selecione o estadopara exibir as informações que deseja.</label>
<select class="Test" name="tEst" id="estados">
<option value="Selecione"> SELECIONE</option>
<option value="ac"> Acre</option>
<option value="al"> Alagoas</option>
<option value="ap"> Amapá</option>                               
</select>

(And then all the states go on.)

  • You would have to use something with database for when you chose "Acre" it would make a Select in the database and return to you and you would put the information in the box.

  • I think it is impossible to do this using only HTML.

  • I’ve seen an example of this code using html, but I can’t remember which site. .

  • If you want to use only Javascript + HTML gives quietly

  • @Sorack is complicated because I don’t really understand java. Is there an article you can send me?

  • IS Javascript only. Only from the same browser side. I will post an answer as it would look as an alternative method if no one gives you an answer with only HTML

Show 1 more comment

1 answer

3


From what I understand of your question, you want to use only the side of client, then if you can use Javascript, as an alternative, I advise you to use Angularjs that would simply solve your problem. Your code would look like this:

(function() {
  'use strict';

  angular
    .module('appEstados', []);

  angular
    .module('appEstados')
    .controller('EstadoController', EstadoController);

  EstadoController.$inject = [];

  function EstadoController() {
    var estado = this;
    estado.opcoes = [];

    iniciar();

    function iniciar() {
      estado.opcoes = [];
      estado.opcoes.push({nome: "Acre", informacoes: "O Acre é um estado que começa com A"});
      estado.opcoes.push({nome: "Alagoas", informacoes: "O Alagoas é um estado também que começa com A"});

      estado.seleciona = estado.opcoes[0];
    }
  }
})();
  <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>

<div ng-app="appEstados">
  <div ng-controller="EstadoController as estado">
    <label class="estados">Selecione o estado para exibir as informações que deseja.</label>
    <select ng-options="opcao.nome for opcao in estado.opcoes" ng-model="estado.selecionado"></select>

    <br>
    <br>

    {{estado.selecionado.informacoes}}
  </div>
</div>

  • 1

    It worked great! Just takes away a doubt, if I want to edit the information, would have how? In case, change font, font size and etc, in css. What class would I have to use? Because the information is in Java right.

  • @Inezboldrin you can apply CSS normally, it’s just HTML + Javascript. You know how to do this?

  • 1

    Yes, I know how to use CSS. However, the class of information I don’t know what is.

  • 1

    @Inezboldrin I did not put any class, but just you change the HTML and put ^^

  • 1

    I made the change I needed. I used the states as an example, to simplify the issue. But I am doing with neighborhoods, but still containing information, in this case are establishments, addresses and phones.

  • 1

    And for example, I have to put two pieces of information inside the same neighborhood, it’s the same procedure?

  • That’s right, just add one more property and another location to show the information

  • 1

    So if in Bairro Botafogo I want to add two different information, I would have to do the following: bairro.opcoes.push({name: "Botafogo", informacoes: It is a neighborhood of the South Zone of the city of RJ." And to add the second information, it should be: ", informacoes: "Onde se localiza o clube , Botafogo de Futebol e Regatas"}); or have some way to do direct but with line breaking? I’m a little lost

  • 1

    @Inezboldrin you would do the following bairro.opcoes.push({nome: "Botafogo", informacoes: É um bairro da Zona Sul da cidade do RJ.", informacoes2: "Onde se localiza o clube , Botafogo de Futebol e Regatas"});. And in HTML would put a {{bairro.selecionado.informacoes2}} where you want the second part of the information to appear. Line break is \n in the text.

  • 1

    Ah I got it! It was certainly my reasoning was not so wrong. Thank you!!!

  • you helped me solve this issue, but the execution of the code is no longer as before. You could help me?

  • You can create a new question with your new doubts so you can fully understand it

Show 7 more comments

Browser other questions tagged

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