1
Hello I wanted to format the date of my form on the page loading, because the date is coming from the database in international format (yyyy-mm-dd).
I did this function to format my date, however I have 2 forms on the same page and both have inputs of the same name. My input is in text format.
function formataData(ele){
var value = $(ele).val();
var d = undefined;
if(value.search('-') > -1){
d = $(ele).val().split('-');
console.log(d);
} else if($(ele).val().search('/') > -1) {
d = $(ele).val().split('/');
console.log(d);
}
if(d !== undefined){
if(d[0].length > 3){
$(ele).val(d[2]+'/'+d[1]+'/'+d[0]);
}else {
$(ele).val(d[2]+'-'+d[1]+'-'+d[0]);
}
}
}
Summing up what I wanted
-The page loads like this:
<input type="text" name="vencimento" value="yyyy-mm-dd" class="form-control">
-I wanted to call my javascript/Jquery function when loading the page to look like this:
<input type="text" name="vencimento" value="dd-mm-yyyy" class="form-control">
I used $(Document). ready(Function(){}); but it changed too much :/ wanted to reuse this function in other codes! Thanks for your attention.
Note: I had forgotten, I want to call this function for all date fields in page loading also
Why not change the query in the database to give you what you want to start?
– Sergio
It would be better. But what would I call a JS function in the page load? Without having to do it. @Sergio
– Alex
and how you bring the bank date?
– user60252
What language of your page?
– user60252
@Leocaracciolo I’m using PHP, Js/Jquery, Mysql
– Alex
because it does not in php?
– user60252