0

How would I modify the function below to assign a value of whatever the current date is instead of 4/11/2013?

<script type="text/javascript">
$('#FormsPageID table tr:nth-child(12) td:nth-child(2) div span span input')
  .on('focus', function(){
      var $this = $(this);
      if($this.val() == '4/11/2013'){
          $this.val('');
      }
  })
  .on('blur', function(){
      var $this = $(this);
      if($this.val() == ''){
          $this.val('4/11/2013');
      }
  });
</script>
manh2244
  • 133
  • 1
  • 2
  • 15

2 Answers2

1

This would work

var date = new Date();
var strDate = (date.getMonth() + 1) + "/" + date.getDate() + "/" +date.getFullYear()
Parthik Gosar
  • 10,998
  • 3
  • 24
  • 16
0

Building off Parthik's answer, you can make that a function, call it inside the .val()

function getCurrentDate() {
    var date = new Date();
    var strDate = (date.getMonth() + 1) + "/" + date.getDate() + "/" +date.getFullYear()
    return strDate;
}

And in your code, change:

$this.val('4/11/2013');

To

$this.val(getCurrentDate());
tymeJV
  • 103,943
  • 14
  • 161
  • 157