Solved

How do I occupy a text field using javascript?

Posted on 2011-09-16
3
246 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
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…

910 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

22 Experts available now in Live!

Get 1:1 Help Now