date in textbox on page load

 
 

Share on Google+Share on Google+

harsh joshi
date in textbox on page load
2 Answer(s)      5 years and 2 months ago
Posted in : JavaScript Questions

i want to insret the current date in textbox but this code dosen't work and the value of text box will be blank

 <script type="text/javascript">

        function addDate() {

            var mydate = new Date();
            var year = mydate.getFullYear();

            var day = mydate.getDay();
            var month = mydate.getmon() + 1;
            if (month < 10) {
                month = "0" + month;
            }
            var daym = mydate.getDate()
            if (daym < 10)
             {
                 daym = "0" + daym;

            }
             today = day + month + year;
            return today;

        }
        window.onload = function()
        {

            document.theForm.text3.value = addDate();

        }


    </script>

</head>
<body>
    <form id="form1" runat="server">
    <div>

    Today date is : <input type="text" id="txtdate" />
    <INPUT id=text3 name=text3   />


  </div>
    </form>
</body>
</html>
Ads
View Answers

October 3, 2012 at 3:42 PM


Here is a javascript code that insert the current date into textbox on page load.

<html>
<script>
function addDate(){
date = new Date();
var month = date.getMonth()+1;
var day = date.getDate();
var year = date.getFullYear();

if (document.getElementById('date').value == ''){
document.getElementById('date').value = day + '-' + month + '-' + year;
}
}
</script>
<body onload="addDate();">
Today's Date is: <input type="text" id="date">
</body>
</html>


October 4, 2012 at 9:30 AM


thanks


Ads









Related Tutorials/Questions & Answers:
date in textbox on page load
date in textbox on page load   i want to insret the current date in textbox but this code dosen't work and the value of text box will be blank... into textbox on page load. <html> <script> function addDate(){ date = new
get date picker values to a textbox
get date picker values to a textbox  I am using DatePicker to select date in a form in asp.net using c#. I need the picked data to get in to a textbox. Please help me soon
Advertisements
How to display current date in textbox - Date Calendar
;% } This is my problem: I want to display current date in textbox...How to display current date in textbox  Hi guys, I'm really need your... Date(); var month = currentTime.getMonth() + 1; var day
session on page load
session on page load  holding session on page load and reload..   <?php session_start(); if (!isset($_SESSION['arr']['counter'])) { $SESSION['arr']['counter'] = 0; } else { $SESSION['arr']['counter']++; } var_dump
optimze page load - Java Beginners
optimze page load  Hi there My code everything works fine. But i.../calendar.gif", buttonText: "Due Date", buttonImageOnly: true...", buttonText: "Due Date", buttonImageOnly: true}); }); function onLoad
keeping log of page load - Java Beginners
keeping log of page load  Hello, I have a project and I need... on is developed by someone else. The problem with this JSP page is that sometime it loads very nicely but sometimes it doesn't load proper way and it times out. I
HOW TO DISPLAY ID IN TEXTBOX BASED ON COMBOBOX SELECTION IN A SAME PAGE
HOW TO DISPLAY ID IN TEXTBOX BASED ON COMBOBOX SELECTION IN A SAME PAGE ... SystemAdmin 2 Office Bearer Am loading this Rolename into one page called... is how to get Roleid in textbox when i select Role_name from combobox in a same
pre Page load display an image loading - JSP-Servlet
pre Page load display an image loading  hi, We have requirement some pages are loading very slow, while the page is processing we need...;Hi Friend, Do you want to display image before loading page? Please clarify
how to load a table of data from oracle, to a jsp page using hashmap.
how to load a table of data from oracle, to a jsp page using hashmap.  I have a jsp page which ask for project ID,team name,member name according to this data i have to retrieve their details from the database(oracle). I have
Form Should not load
Form Should not load  I have a jsp page which has textbox and dropdown box, when I submit it, the page reloads and the textbox and dropdown box also... box after submitting or the form should not load again. Thanks in adbance
passing textbox value from one page to another page using html n javascript
passing textbox value from one page to another page using html n... of variable at onclick event of button and also want to print it in textbox on the othe (next/prevoious)page please help me   1)page1.html: <html>
Calendar window is not showing the textbox values for the Dynamic rows in html page - Java Interview Questions
Calendar window is not showing the textbox values for the Dynamic rows in html... is not showing in textbox please help to me it is very urgent for me Add...: 1.0 // Date: 12-05-2001 (mm-dd-yyyy) // Author: Denis Gritcyuk ; // Notes
Addintion in year fields of sql date in a java page
Addintion in year fields of sql date in a java page  In my database i have a field StartDate and EndDate Now entering date from my jsp..., HttpServletResponse response) throws ServletException, IOException { Date
Ajax Load
Ajaxload The ajaxload is a tool, which follow web2.0 standard. Due to slow Internet speed or delay some times data takes time to load. At this time we... the image and can use this image directly in your web page
jQuery Ajax load request
jQuery Ajax load request  Hi, How to use jQuery to send the request on server to load data in web page? Thanks   Hi, In the jQuery Load... and then load the data in web page. Thanks
date
date   how to insert date in database? i need coding
date
date  can u tell me how to calculate difference between a user provided date and the system date in java
date
date  can u tell me how to calculate difference between a user provided date and the system date in java
date
date  i want difference between the date entered in a jtextfield and the system date in java
Load UIImage from URL
Load UIImage from URL  Load UIImage from URL
how to load pdf on html
how to load pdf on html  how to load pdf on html
Load Icon Image Exception
Load Icon Image Exception  Load Icon Image Exception
date
database table name birthday (DOB date); dob with DATE data type in database while... JSP Page Hello World...=d.getTime(); java.sql.Date date = new java.sql.Date(t); try
date
date  how to insert date using html through the combobox
date
date  how to insert date using html through the combobox
date
date  how to insert date using html through the combobox
date
date  how to insert date using html through the combobox
J2me Map load error
J2me Map load error  Hi , i am making a POC to load google map in my mobile,now i m getting the address of location by its lattitude and longitude in web page , but thing is i wana to store in my net beans emulator , its showing
Write an Applet which display current date and time on the web page??
Write an Applet which display current date and time on the web page??  Write an Applet which display current date and time on the web page??  Here is an applet code that display date and time. import java.applet.
Write an Applet which display current date and time on the web page??
Write an Applet which display current date and time on the web page??  Write an Applet which display current date and time on the web page?  Here is an applet code that display date and time. import java.applet.
nsstring load from file
nsstring load from file  Hi, How to load file data into NSString object? Example of nsstring load from file, basically the html file data into NSSTring object. Thanks

Ads

 
Advertisement null

Ads