Jump to content

Recommended Posts

I am trying to update the text in a span with a date (which is working fine), but I also want to format that date before it is updated in the span. For example, in the text area I input a date (format: YYYY-MM-DD HH:MM:SS), and I'd like to output between the span tags M-D-YYYY. Does that make sense? I'm totally lost here and hoping someone can help me out.

 

Here is the javascript.

 

function show_post_date() {
var ele = document.getElementById("post_date");
var text = document.getElementById("new_post_date");

// Get the date value, then format it
var formatted_date = ele.value;

// THIS IS WHAT I'VE TRIED, BUT NOTHING IS UPDATED INTO THE SPAN IF I INCLUDE THIS
var curr_date = formatted_date.getDate();
var curr_month = formatted_date.getMonth();
var curr_year = formatted_date.getFullYear();
formatted_date = curr_date + "-" + curr_month + "-" + curr_year;
// END SECTION OF WHAT I'VE TRIED

if(ele.value != "") {
	text.innerHTML = formatted_date;
  	}
}

 

Here is the element

 

When: <span id='new_post_date' style='font-weight:bold;'></span>
<input type="text" name="post_date" id="post_date" value="" onChange='show_post_date()' />

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.