Solved

How do I occupy a text field using javascript?

Posted on 2011-09-16
3
251 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 55

Expert Comment

by:Huseyin KAHRAMAN
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 55

Accepted Solution

by:
Huseyin KAHRAMAN 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Avoid defining the variables in the global scope; trying to define them in a local function scope. Because:   • Look-up is performed every time a variable is accessed.   • Variables are resolved backwards from most specific to least specific scope…
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…

717 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