How can I change an HTML page dynamically?

Asked

Viewed 25 times

0

Good morning!

I am creating an html page, which will serve to make feedback, that is to say to report specific situations or under certain conditions ask for help. It turns out that this page immediately asks for some essential information and later asks to select a theme. By selecting this theme it can come to two situations

  1. Displays another selectbox on the page to select sub-theme
  2. Or submit another form

I’m using javascript to do this, but I don’t really know how to do it, I feel difficult. Below I show the code already made by me:

<div class="work-post">

                                <div class="work-post-content searchw" id="firstSelect">
                                <form action="" method="post">
                                <select name="select" id="selectFirstHelp" class="formatform search-format" onChange="selectHTML(this)">
                                    <option class="search-format" value="Portugal,PT">Por favor selecione uma categoria</option>
                                    <option class="search-format" value="Reserva/Gestão de Reservas">Reserva/Gestão de Reservas</option>
                                    <option class="search-format" value="Lisboa">Senhor</option>
                                    <option class="search-format" value="Faro">Senhora</option>
                                    <option class="search-format" value="Faro">Meritissima(o)</option>
                                    <option class="search-format" value="Faro">Senhor prof.</option>
                                    <option class="search-format" value="Faro">Senhora prof.</option>
                                  </select>
                                  <script>
                                  function selectHTML(x){
                                    var value = x.value;
                                    var newBox = document.getElementById('selectSecondHelp');
                                    //var getBox = document.getElementById('selectSecondHelp');
                                    if(value=="Reserva/Gestão de Reservas")
                                    {
                                        //Quando seleciono um valor concreto 
                                        //Quero alterar as outras boxes abaixo ... ou mesmo ocultar-las
                                        //Poderei ainda aqui ter de apresentar novo formulário abaixo
                                        function ChangeBox(newBox);     
                                    }

                                  }
                                  function ChangeBox(y)
                                  {
                                     var index=0;
                                     for (index=0; index<=y.length; index++)
                                     {
                                         if(index>=1)
                                         {
                                             alert("Teste");
                                             /*Se primeiro item é [1]*/
                                             if(index[1])
                                                document.getElementById('selectSecondHelp').value="Reservas Atuais";
                                             //Se determinado valor for selecionado posso ter de criar abaixo novo 
                                             //formulário ou adicionar uma terçeira tag select 
                                         }
                                     }
                                  }
                                  </script>
                                </div>                              
                            </div>

Below this "select", I have another "select", with more options, but depending on the values selected in the first "select", I must show the second "select" changed, hide the second "select", or even hide the second "select" and create a new form.

The page: https://www.lufthansa.com/xx/en/Feedback?level1=2&level2=4 , have a very concrete example of what I intend to do.

I wonder if you could help me

Thanks in advance

  • This is a relatively common problem and there are already some answers about it (here, or here among others. Can you make a JSON (or a simple scheme) of what are the sub-options? How do you send the form? by ajax or html POST?

  • The form is being sent by POST ... Saved error

No answers

Browser other questions tagged

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