user2554201
user2554201

Reputation: 33

javascript to update Joomla text field on page load

When a page loads, I need to add the current date in this format (mm/dd/yyy) into a Joomla form field using javascript. (the form extension does not have ability to do this) The field ID=938.

I tried using this code, but it is not working in Joomla so I assume there's a special code:

<script>
   document.getElementById('938').value = (new Date()).format("mm/dd/yyyy");
</script>

Any help is appreciated.

Upvotes: 0

Views: 106

Answers (1)

Tushar Gohel
Tushar Gohel

Reputation: 254

JSN Uniform does not provide any option to display current date on field, so you can try following code.

var today = new Date();
var dd = today.getDate();
var mm = today.getMonth()+1;
var yyyy = today.getFullYear();
if(dd<10){
    dd="0"+dd
} 
if(mm<10){
    mm="0"+mm
} 
var today = mm+"/"+dd+"/"+yyyy;             
document.getElementById('938').value = today;

Upvotes: 2

Related Questions