Set up a select without using php?

1

I currently have a situation that really may not be the big deal, but I have tried to search everywhere and I really have not found the answer to my problem.

Well, we all know that the <select> tag is used to create a list of <option> , I am working in JavaScript with a code based on HTLM, since I am doing a page with dynamic elements that do not need to reload the page for to fulfill its function, for that reason I do not want to put PHP to the code, since PHP needs to reload the page for its functions, the problem is that I have no idea what to do after defining the possible options of the select.

<select id="opcion" required>
  <option value="1">boton 1</option>
  <option value="2">boton 2</option>
</select>

What I would like to do is that when selecting the first option, show a button and then if I press the second option, hide the first button and create a new one.

The buttons if I know how to configure them, really this question is simple and short, but I can not find anywhere to apply the conditions of the select, try with a IF , but nothing happened.

    
asked by Gabriel 25.09.2018 в 23:44
source

1 answer

1

This question has already been answered in at least one question in English: Jquery enable / disable button based on select option

$('#picker').on('change', function() {
    $('#' + $(this).val()).prop('disabled', false)
      .siblings().prop('disabled', true);
});​

With that answer, an example is included: link

In your case, if you want to hide the buttons, you can use show / hide:

$('#picker').on('change', function() {
    $('#' + $(this).val()).show()
      .siblings().hide();
});​
    
answered by 26.09.2018 / 00:12
source