473,396 Members | 2,036 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

how to preloading a text field when a certain button is pressed?

I have a little program here that I think would simulate something close to what I'm trying to do. I'm assuming if I can make it work, I can get the big stuff to work. I have a form, that basically allows you to select a radio button. When the button is pressed, I want to preload my date field text boxes. But their values are staying blanked out when I go and populate the page. So I tried to write a very small program included here that would put the current year in the date text box when I click the checkbox. It's date text box stays blank as well. What am I doing wrong?
Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  5. <title>Untitled Document</title>
  6. </head>
  7. <script>
  8. function addDate()
  9. {
  10. alert("enetered addDate");
  11.     var now = new Date();
  12.     myYear = now.getYear();
  13.     var element = document.getElementsByName("date");
  14.     element.value=myYear;
  15. }
  16. </script>
  17. <body>
  18. <form action="something" method="get">
  19.   Name: <input type="text" name="fullname" /><br />
  20.   Email: <input type="text" name="email" /><br />
  21.   date: <input type="text" name="date" value="mm/dd/yyyy" /><br />
  22.   <input type="checkbox" value="Submit" onclick="addDate()" />
  23. </form>
  24.  
  25. </body>
  26. </html>
  27.  
Mar 31 '10 #1
1 2416
gits
5,390 Expert Mod 4TB
getElementsByName returns a node list ... so you need to reference a node like:
Expand|Select|Wrap|Line Numbers
  1. var element = document.getElementsByName("date")[0];
kind regards
Mar 31 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Dave B | last post by:
Does anyone know of a program that will read a text file and fill in a web form with the contents of that file? We need to get about 3000 records (5 fields to each record) into a database owned by...
2
by: Juan Garcia | last post by:
Subject says it all. Given: Window A with text field. Window B with a button (onClick opens Window C) Window C with a button (onClick I want it to modify text fields of Window A) I have...
22
by: Fabian | last post by:
var preload1 = new Image(); preload1.src = "/pic/yay.gif"; var preload2 = new Image(); preload2.src = "/pic/nay.gif"; The above is meant to preload image files, yes? Problem is, it doesnt seem...
1
by: John English | last post by:
Is there a way to catch the Enter key being pressed in a text field? I want to submit the form if Enter is pressed in a particular field. I have more than one form on the page, each with a submit...
0
by: DL | last post by:
Hi, I have an app. that opens pdf documents. Now i would like to use the text selectiontool of the pdf interface to select text and then when a user presses a button it should automatically copy...
2
by: Julie | last post by:
Hi, I'm trying to change images on a website without reloading the whole page and use the following code to preload the images: var preloadFlag = false; function preloadImages() { if...
8
by: Ryan | last post by:
I have a hidden field as such: <INPUT TYPE=\"hidden\" name=xmlfield > I have a button that i want to use to call a function to change the value: <INPUT TYPE=submit VALUE="Display XML"...
40
by: Geoff Cox | last post by:
Hello, I am still having problems - apologies if the answer is in previous postings! I now have, in the header, <sctipt> var myimages=new Array();
1
by: chris | last post by:
I'm not sure this is even feasible. What I want to do is create a command button. When this command button is pressed, it taes field values and puts them into text format. I think I know how to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.