Is it possible to pop up a html element? - javascript

My requirement is like I have a textarea which is disabled. On click of a button the user should be prompted for a datetime and it should be appended to the textarea value with a newline so that I can read it later one by one. Because I need to store these datetime values in an xml file which would be used to remember these values.
I am looking for a way to get a datetime input on click of a button. I thought to popup a datetime element to get the input using jquery. But I am not sure will it work or not. Is there any way to do it ?
<textarea id="schedule" name="schedule" placeholder="Mailing Schedule's" class="inputarea" disabled="disabled"></textarea>
$('#addschedule').click(function(){
var schedule=prompt("Enter Schedule");
var val = $("textarea#schedule").val();
if(val!="")
$("textarea#schedule").val(val+"\n"+schedule);
else
$("textarea#schedule").val(schedule);
});
I tried it for text input. But I dont know how to do it for datetime. Sorry If its not that good question. But some help would be appreciated.

$(function(){
$('button').click(function(){
var d = new Date();
var t = d.toLocaleTimeString();
var mL = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
var mS = ['Jan', 'Feb', 'March', 'April', 'May', 'June', 'July', 'Aug', 'Sept', 'Oct', 'Nov', 'Dec'];
var week = ["Sunday", "Monday", "Tuesday", "Wednesday","Thursday", "Friday", "Saturday"];
var day = week[d.getDay()];
var date = d.getDate();
var month = mL[d.getMonth()];
var year = d.getFullYear();
var total = day+' '+date+' '+month+' '+year+' '+t+'\n';
var schedule=prompt("Enter Schedule", 'here');
var val = $("textarea#schedule").val();
if(val!=="")
$("textarea#schedule").val(val+'\n'+total+' '+schedule);
else
$("textarea#schedule").val(total+' '+schedule);
});
});

Related

Date format in JavaScript. For example: June 10, 2021 [duplicate]

This question already has answers here:
How do I format a date in JavaScript?
(68 answers)
Closed 1 year ago.
How do I can set the date format to "June 10, 2021"?
I have a small piece of code like this:
var homnay = new Date();
var datehomnay = (homnay.getMonth()+1) + ' ' + homnay.getDate() + ', ' + homnay.getFullYear();
document.getElementById("curDay").innerHTML = datehomnay;
Use this procedure
const MONTHS = ['JANUARY', 'FEBRUARY', 'MARCH', 'APRIL', 'MAY', 'JUNE', 'JULY', 'AUGUST', 'SEPTEMBER', 'OCTOBER', 'NOVEMBER', 'DECEMBER']
const date = new Date()
const dateString = `${MONTHS[date.getMonth()]} ${date.getDate()}, ${date.getFullYear()}`
console.log(dateString)

How to get check for current month in Daterangepicker?

I want to do something like this, I tried multiple ways but I am unable to find it. I am getting start and end date but not the current month. I want current month so it works with all locale
if(CURRENT MONTH){
// Do This
}
use the Date object for get month as follows,
var date = new Date(); // assume date is 10/06/2020
var month = date.getMonth(); // it return month as 10
if you want to get month name, firstly you should declare the array including with months and then get the month name using this array as follows,
var months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
var date = new Date(); // assume date is 10/06/2020
var nameOfMonth = months[date.getMonth()-1] // it return month name as October
then you can use month or nameOfMonth as follows,
if (month == 10){
// Do This
}
if (nameOfMonth == 'October'){
// Do This
}

sum of variable in for(variable in object) loop is resulting in concatenation JavaScript [duplicate]

This question already has answers here:
for( in ) loop index is string instead of integer [duplicate]
(5 answers)
Closed 2 years ago.
i'm new to JavaScript. Im trying to make a loop that prints every month and also numbers them, but i end up getting a concatenation of the numbers. here's my code
var months = ['january', 'february', 'march','april',
'may', 'june', 'july', 'august',
'september', 'october', 'november, 'december'];
for(i in months){
document.write((i+1)+'.- '+months[i]);
document.write('<br >')
}
and my output is like this:
01.- janury
11.- february
21.- march
.... etc
This code will give you the desired result, changing it to a standard for loop:
var months = ['january', 'february', 'march','april', 'may', 'june', 'july', 'august' 'september', 'october', 'november', 'december'];
for (i=0; i < months.length; i++) {
document.write(i+1 + ".- " + months[i] + "<br>")
};

How to bind dropdown values to javascript array?

I am working in MVC and I have to bind dropdown values to an array in javascript. How do I do that?
dropdown list-
Html.DropDownListFor(m => m.MyActivityRequest.ToMonth, Model.MonthNames, new { #id = "monthToSelect" })
Javascript function:
$(document).ready(function(){
$("#yearToSelect").change(function(){
var months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
var date = new Date();
var monthVar = date.getMonth();
var yearVar = date.getFullYear();
if ($(this).val() < yearVar ){
$("#monthToSelect").find('option').remove();
for( i = 0; i < 12; i++ ){
$("#monthToSelect").append($("<option>",{
value: months[i],
text: months[i]
}));
};
}
you can see that the the array- 'months' is hard coded as of now. I want to dynamically bind the dropdown values to this array.
Js Fiddle Demo.
Inside your code place the below code appropriately.
Better Approach:
var months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
var option = '';
for (i=0;i<months.length;i++){
option += '<option value="'+ months [i] + '">' + months [i] + '</option>';
}
$('#monthToSelect').append(option);
Refered from here.
I think you have to pass the month list from controller. So in javascript you can make an ajax call and return the same list of months. You can use this list instead of array- 'months' in your javascript function.

specific time zone with Javascript [duplicate]

This question already has answers here:
How to initialize a JavaScript Date to a particular time zone
(20 answers)
Closed 9 years ago.
This is simple current time zone clock so i want specific time zone like INDIA if any person open my site in US or any Out of India, that people can see INDIAN Time not US time.
So Please Can any one help to add specific time zone in this code.
function date_time(id)
{
date = new Date;
year = date.getFullYear();
month = date.getMonth();
//months = new Array('Jan', 'Feb', 'Mar', 'Apr', 'May', 'June', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec');
months = new Array('January', 'February', 'March', 'April', 'May', 'June', 'Jully', 'August', 'September', 'October', 'November', 'December');
d = date.getDate();
day = date.getDay();
days = new Array('Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat');
//days = new Array('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday');
h = date.getHours();
if(h<10)
{
h = "0"+h;
}
m = date.getMinutes();
if(m<10)
{
m = "0"+m;
}
s = date.getSeconds();
if(s<10)
{
s = "0"+s;
}
result = ''+d+' '+months[month]+' '+year+' - '+days[day]+' - '+h+':'+m+':'+s;
document.getElementById(id).innerHTML = result;
setTimeout('date_time("'+id+'");','1000');
return true;
}
You may use this js timezone-js
for further reference you may refer this Question

Categories

Resources