How to pass a different value in an HTML form?

Asked

Viewed 87 times

3

I am creating an HTML date filter so that the SQL query can return a specific value to me.

I’m just trying to make it difficult to pass on this information because the form option needs to appear month as in <option>Março</option>.

My SQL query looks like this:

select codigo, id_usuario, codigo_usuario, data, hora, despesa, valor, modo, observacao, estabelecimento, genero, tipo from despesa where id_usuario = 1 and data between '2015-Março-01' and '2015-Março-31' ;

I wish I could select in the form the option March and he change this month by the number 03, so I can do a select certinho.

I just wanted to know if there is an easier way to do this right in the HTML form.

Thank you.

2 answers

9


Just add a value to your option. See:

$(document).on('change', '#meses', function(){
  var mes = this.value;
  alert(mes);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<select id="meses">
  <option value="01">Janeiro</option>
  <option value="02">Fevereiro</option>
  <option value="03">Março</option>
  <option value="04">Abril</option>
  <option value="05">Maio</option>
  <option value="06">Junho</option>
  <option value="07">Julho</option>
  <option value="08">Agosto</option>
  <option value="09">Setembro</option>
  <option value="10">Outubro</option>
  <option value="11">Novembro</option>
  <option value="12">Dezembro</option>
</select>

-3

Currently it is best to use HTML5 Datepicker. It will allow you to select the date and will pass it already formatted as the server works. In the case there in particular you will have to treat the dates, and take the month, from 2015-March-01 and serialize. The return starts at 0 not at 1. So if you use datepicker you will already be able to select the direct date and month in the input, to send or receive from your request via sql .

  • 1

    Hello @David. Try putting code that supports your answer, even if it’s just an example. It’s easier to understand.

  • 2

    You’re talking about the input type date? Because if it is, not all browsers accept.

  • Buddy, you’re regulated by W3. https://www.w3.org/TR/html52/sec-forms.html#date-time-and-number-formats Stackoverfow in English is garbage !

Browser other questions tagged

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