hidden input wont pass to database - javascript

I'm trying to date when something is submitting into my database. This isn't working, no errors, just puts nothing into the database.
I have in the body...
<input type="hidden" id="thedate" name="DateModified">
<script type="text/javascript">
function getDate()
{
var date = new Date();
var day = date.getDate();
var month = date.getMonth() + 1;
var year = date.getFullYear();
if (month < 10) month = "0" + month;
if (day < 10) day = "0" + day;
var today = month + "/" + day+ "/" + year;
document.getElementById('thedate').value = today;
}
</script>
Then, at the bottom of the page before </body> I have...
<script type="text/javascript">
GetDate();
</script>
The form is...
<form method="POST" action="blabla.asp">
Everything else in my form goes to the database, just not the date.

Try the following:
Change GetDate() to getDate()
Make sure that you are reading "DateModified" in the server instead of "thedate" field.
I'd also suggest that you get the timestamp (UTC) in the server instead from the client's browser. Anyone can post to the url using tools like postman etc and send in bogus timestamp.

Just change your bottom script looks like below code.
<script type="text/javascript">
GetDate(); // wrong
getDate(); // right
</script>

Related

Pre-populate Form Field With The Internal Millisecond Clock From Javascript

I have a form on my website that I need to pre-populate with the current unix millisecond timestamp.
I do have another form field (in the same form) which successfully pre-populates the Date (Month, Day, Year) with the following code:
<div>DATE<br><input name="date" id="date"></div>
<script>
(function() {
var days = ['','','','','','',''];
var months =
['Jan','Feb','Mar','Apr','May','June','July','Aug','Sept','Oct','Nov','Dec'];
Date.prototype.getMonthName = function() {
return months[ this.getMonth() ]; };
Date.prototype.getDayName = function() {
return days[ this.getDay() ]; }; })();
var now = new Date();
var day = now.getDayName();
var month = now.getMonthName();
document.getElementById('date').value = day + ' ' + month + ' ' +
now.getDate() + ', ' + now.getFullYear();
</script>
However... I'm not having the same luck when attempting to pre-populate a second form field with the Unix Millisecond timestamp using this code:
<div>TIMESTAMP URL<br><input name="timeStampURL" id="timeStampURL"></div>
<script>
var d = new Date();
document.getElementById('timeStampURL').innerHTML = d.getTime();
</script>
I don't understand why the two codes behave differently that way, but any advice as to how to get that script to pre-populate the field would be appreciated.
Input elements don't have any content, so setting their innerHTML property does nothing. Your first function is setting the value attribute, so should your second:
function showTimeValue() {
document.getElementById('timeValue').value = Date.now();
}
window.onload = showTimeValue;
<input id="timeValue">
<button onclick="showTimeValue()">Update time value</button>
Each time you run the code, you'll get an updated value.

hide javascript dates in table

i have a form where the previous dates from today must be hidden in the first date picker and the second date picker must not show dates previous to the first selected date.
Date picker one
Date picker two
The form is working for the first row but i can't get the code to work for the other rows that follow when i "add" a new row.
Can anyone assist me with this Please?
here is my current code :
$(document).ready(function(){
function updateMinimumEndDate ()
{
var minimum = $('.DepartDate input').val();
var minSplit = [];
minSplit = minimum.split("/");
var newMin = (minSplit[2]+"-"+minSplit[0]+"-"+minSplit[1]);
$('.ReturnDate input').attr('min',newMin);
}
$('.DepartDate input').change(updateMinimumEndDate);
});
$(function() {
$(document).ready(function () {
var todaysDate = new Date();
var year = todaysDate.getFullYear();
var month = ("0" + (todaysDate.getMonth() + 1)).slice(-2);
var day = ("0" + todaysDate.getDate()).slice(-2);
var minDate = (year +"-"+ month +"-"+ day);
$('.DepartDate input').attr('min',minDate);
});
});
The problem is with the line
$('.DepartDate input').change(updateMinimumEndDate);
This needs to be in docReady. It also needs to use the jQuery function .on so that it will be triggered for new rows as they are added. I haven't checked this:
$('.DepartDate input').on('change', 'AnchorSelector', function() {updateMinimumEndDate())};
where AnchorSelector is a location which contains your form.

How to select current day when user was in other months in Datepicker calender by using a clickable button.?

I have an event calender in my magento website.
I need to redirect users to current date while they are in other months.
I have a button called TODAY to write the click event.
EX : now I am in month of march, I want to go to February by clicking the button TODAY.
Please see the image I will post here.
I am unable to publish an image, if any one nee an image for this I can send it to you.
Great pleasure if any one can help me on this. Thank you.
EDIT
<link rel="stylesheet" href="http://code.jquery.com/ui/1.11.2/themes/smoothness/jquery-ui.css">
<script src="http://code.jquery.com/ui/1.11.2/jquery-ui.js"></script>
jQuery(function() {
var jqdpopup = jQuery('#event_popup').dialog({autoOpen: false});
var myDate = new Date();
var prettyDate =(myDate.getMonth()+1) + '/' + myDate.getDate() + '/' +
myDate.getFullYear();
jQuery("#date_input").val(prettyDate);
jQuery('.eventslisting_title span').html(prettyDate);
getevents(prettyDate);
var datesArray=["11/02/2014","11/03/2014"];
jQuery(function(){
jQuery('#event_calender').datepicker({
inline: true,
beforeShowDay: function (date) {
var theday = (date.getMonth()+1) +'/'+
date.getDate()+ '/' +
date.getFullYear();
return [true,jQuery.inArray(theday, datesArray) >=0?"eventDate":''];
},
onSelect: function(date, obj){
jQuery('#date_input').val(date); //Updates value of of your input
jQuery('.eventslisting_title span').html(date);
getevents(date);
jqdpopup.dialog( "open" );
}
});
On today button click event, write this code
$('#event_calender').datepicker('setDate', 'today');
Check out the setDate method in the datepicker api: http://api.jqueryui.com/datepicker/#method-setDate
To set the date by clicking a button do this:
jQuery("#buttonID").click(function(){
jQuery('#event_calender').datepicker( "setDate", "today");
});

Inserting JavaScript code for today's date in a textarea tag

I'm trying to insert today's date into a text area tag. Is it possible to do this? This is part of a response form. In the past we have entered today's date manually. However here it just turns my JS code to text. Thank you.
<i><b>Response:</b></i><br><textarea cols=65 rows=10 name="feedback" wrap="hard" tabindex="12" >
<script type="text/javascript">
var d = new Date()
document.write(d.getMonth() + 1)
document.write("/")
document.write(d.getDate())
document.write("/")
document.write(d.getFullYear())
</script>
CURRENT DATE
Response text.................
</textarea><br><br>
You can do something like this:
JSFiddle
<textarea></textarea>
<script>
var d = new Date(),
month = d.getMonth() + 1,
date = d.getDate(),
year = d.getFullYear(),
area = document.getElementsByTagName("textarea")[0];
area.value = month +"/"+ date +"/"+ year;
</script>
I hope this is what you mean:
<script type="text/javascript">
var d = new Date()
document.write(d.getMonth() + 1)
document.write("/")
document.write(d.getDate())
document.write("/")
document.write(d.getFullYear())
</script>
<i><b>Response:</b></i><br><textarea cols=65 rows=10 name="feedback" wrap="hard" tabindex="12" >
Response text.................
</textarea><br><br>
It will output 5/16/2014 Response: and then the textarea which is empty (except for the Reponse text............................)

JavaScript that prints date and time with a link won't work

I'm currently enrolled in a JavaScript class at my community college, and we're supposed to create a page with the following:
"Today's date is (date)"
"Kids Club"
"The time is (time)"
Then, I don't seem to get this part, the instructions state: "Have a link to the new kidsnew.htm page that contains the text "Go To Kids Club". Use onClick and widow.location to open kidsnew.htm.
Before switching, you should use the navigator object and the method to test for the name and version of the browser. Display the name and version of the browser with an alert box and advise the user to upgrade for better results with the new page if their browser is out of date.
The kidsnew page should contain an HTML form button that will take you back to the "kidsold.htm" page."
So. I assume that I'll need the browser verification, where you can find in the first part of the code. I don't get what else I'm supposed to be using, as we were not told of a "onClick" method in the chapter's were reading. Can anyone help me refine the code and get it to display as stated? I did most of it correctly, I think;
Here's my code:
<html>
<head>
<title>Kids Club</title>
<script type = "text/javascript" src = "brwsniff.js"></script>
<script type = "text/javascript">
<!-- hide me from older browsers>
//==============================Browser Info=================================
var browser_info = getBrowser();
var browser_name = browser_info[0];
var browser_version = browser_info[1];
var this_browser = "unknown";
if (browser_name == "msie")
{
if(browser_version < 5.5)
{
this_browser = "old Microsoft";
}
else
{
this_browser = "modern";
}
}
//end
if (browser_name == "netscape")
{
if (browser_version < 6.0){
this_browser = "old Netscape";
else
{
this_browser = "modern";
}
} //end
</script>
//=========================End Browser Info============================
//==========================Start Date Script============================
var date = new Date();
//new is keyword for object Date
//
//getting info from object Date
//
var month = date.getMonth();
var day = date.getDate();
var year = date.getYear();
var hour = date.getHours();
var minutes = date.getMinutes();
//january is month 0, think of arrays
//
month = month + 1;
//fix y2k
//
year = fixY2k(year);
//fix minutes by adding 0 infrotn if less than 10
//
minutes = fixTime(minutes);
var date_string = month + "/" + day + "/" + year;
var time_string = hour + ":" + minutes;
var date = "Today is " + date_string";
var time = "The time is " + time_string;
//y2k fix
//
function fixY2k(number) {
if (number < 1000){
number = number + 1900;
return number;
}
//time fixer
//
function fixTime(number){
if(number < 10) {
number = "0" + number;
}
return number;
}
//========================End Time Script==================================
// show me -->
</script>
</head>
<body>
<script type = "text/javascript">
<!-- hide me from older browsers
document.write(date);
</script>
//show me -->
<h1>Kids Club</h1>
<script type = "text/javascript">
<!-- hide me from older browsers
document.write(time);
</script>
//show me -->
</body>
</html>
Some comments:
> <script type = "text/javascript">
> <!-- hide me from older browsers>
That's rubbish, HTML comment delimiters were never needed to hide script element content, just remove them.
> var year = date.getYear();
You should use the getFullYear method, it avoids the two digit year issue.
> var date = "Today is " + date_string";
There is no need to declare date a second time. It's not harmful, just unnecessary. date started out as a Date object, now it's a string. That's not good programming style, just modify the existing date_string, e.g.
date_string = "Today is " + date_string";
In the body of the page you have:
> <script type = "text/javascript">
> <!-- hide me from older browsers
> document.write(date);
> </script>
> //show me -->
Note that the comment delimiters start inside the script element, then finish outside it. So the browser is left with invalid HTML and whatever happens next is a result of error correction (the same for the next script element too).
Fix that and you may have solved your problem.

Categories