Hi everyone,

I'd like to be able to insert a dynamically updated date into body text that is *always* one day in the future. (for a "time limited" special offer). Do any of you know how I might do that please?

thanks

Comments

marcvangend’s picture

I think the easiest way would be to write some custom javascript that places a button right after the text area and appends the string to the text area value when the button is clicked. This assumes that you have plain text fields; if you're using a wysiwyg editor, it's probably more difficult (but still doable once you understand how wyisiwyg plugins work).

If is not necessary that the date is in the body text, you could use a computed field (http://drupal.org/project/computed_field).

Nick Wilson’s picture

Thanks Marcvangend. Here's what I came up with in the end from some snippets on the web.

<script type="text/javascript">
var today=new Date()
today.setDate(today.getDate()+1)
var theyear=today.getFullYear()
var themonth=today.getMonth()+1
var thetoday=today.getDate()
document.write("<strong>"+themonth+"/"+thetoday+"/"+theyear+"</strong>")
</script>
marcvangend’s picture

Looks like a good start to calculate the date. Now, instead of the document.write, write some jQuery to add the button, add a click event to the button and change the value of the field when the button is clicked.