Solved

How do I occupy a text field using javascript?

Posted on 2011-09-16
3
243 Views
Last Modified: 2013-11-11
I am trying to occupy a text field (t_employment__start_date)on my aspx web page using javascript.  The function is contained in another file that the page calls (I know this is mapped correctly because another function is used and working correctly on the page).  This is the javascript function I created:


function PopulateDate()
{
var currentTime = new Date();
var month = currentTime.getMonth() + 1;
var day = currentTime.getDate();
var year = currentTime.getFullYear();
document.getElementById('t_employment__start_date').value =(month + "/" + day + "/" + year);
}


Attached is the source for the web page

Any advice? Thanks.
pagesource.htm
0
Comment
Question by:neilsav
  • 2
3 Comments
 
LVL 1

Author Comment

by:neilsav
ID: 36550610
Sorry I forgot to mention I am trying to display the current date
0
 
LVL 51

Expert Comment

by:HainKurt
ID: 36550831
nothing wrong in this script
<input id='t_employment__start_date'>
<script>
function PopulateDate(){
  var currentTime = new Date();
  var month = currentTime.getMonth() + 1;
  var day = currentTime.getDate();
  var year = currentTime.getFullYear();
  document.getElementById('t_employment__start_date').value =(month + "/" + day + "/" + year);
}
PopulateDate()
</script>

Open in new window

0
 
LVL 51

Accepted Solution

by:
HainKurt earned 500 total points
ID: 36550839
just make sure you call PopulateDate() after html element, or call this function on body onLoad event

<body onLoad="PopulateDate()">
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Today I would like to talk about localizing (Internationalization) JavaScript applications. Introduction When creating an application that is going to be used by many people around the globe, it is important to remember that not everyone speak…
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now