Pick predefined value and assign in another field

Asked

Viewed 111 times

-3

Talk guys, I have the following problem:

I need to take a date value already set so 2017-06-30 (YEAR-MES-DAY) and play it in another countdown script with the following parameters:

year: 2017, Month: 6, day: 30,

In other words, it is necessary to take the YEAR, MONTH and DAY and play in these fields, plus a COMMA. This date is already scheduled to end the promotion of an X product and always in the same format.

  • Where does the date come from? See if the comment above helps you - if it doesn’t help, please include your code in the question.

  • Ok, I have already put that the date comes predefined from another field and returns this string as text. 2017-06-30 and need to divide and play in another field year: , Month:, day: ,

  • Please mark the answer as accepted, if it solved your problem. And take the tour!

1 answer

0

Where will this date come from? Will it be a form where the user will enter the date? If so, then you don’t even need to use jQuery, just enter a field of the type date in the form, as shown below:

<form action="pagina.php" method="POST">
  <input type="date" name="data" id="data">
</form>

Obs.: Although in the field the date appears in DD/MM/YYYY format, when you receive the value entered in the field it will come in YYYY-MM-DD format. From there, it will be enough to separate the date values with the function of the explode of PHP:

$data = $_POST['data'];
$partes = explode("-", $data);
//      ANO            Mês              DIA
//    $partes[0]     $partes[1]      $partes[2]
$day = $partes[2];
$month = $partes[1];
$year = $partes[0];

Edit: How do you get that date? If it comes from the bank, after storing it in a variable, you can pass it to the script and then dismember the date the way you need it:

var data = "<?php echo $data; ?>";
var array = data.split("-");

var day = array[2];
var month = array[1];
var year = array[0];

  • No friend, this date is already obtained automatically (because I finish the promotion in the registered product) and returns me the value example: 2017-06-30 Ai of this variable I would need to divide and play in these fields in another script: year: , Month: , day: ,

  • @Rafaelmeirim I edited the post, see if this meets what you need.

  • 1

    It worked well friend, I used so: <script type="text/javascript"> var data = "2017-06-01"; var array = data.split("-"); $(Document). ready(function(){&#xA;&#xA; --------------------------------------------------------- */&#xA; $('#timer_with_given_timezone'). syotimer({ lang: by', year:array[0], Month:array[1], day:array[2], hour: 00, minute: 00, }); </script>

Browser other questions tagged

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