I have a webdateedit control. On the page load I want to set a date to that control through javascript. I have tried the following but its not working,
var userid='<%=Session("userid").toString %>'; // 20-Dec-2013
var strdate=dtsheet.split("-");
var sheetdate =new Date(strdate[2] +"/"+ changemonth(strdate[1]) +"/"+ strdate[0]); //changemonth will give 12
dtpstartdate.setDate(sheetdate.getDate); //it is not working
design:
<c1i:C1WebDateEdit ID="dtpstartdate" runat="server" OnClientdateChanged="javascript:enable(true);" WebCalendar="postartdate" OnDateChanged="dtpstartdate_DateChanged">
</c1i:C1WebDateEdit>
What could be the reason?
I suggest you start by looking at the html produced by C1WebDateEdit control. Then find the input which holds the date value.
Once you found it change the javascript to set the value of that input.
var userid='<%=Session("userid").toString %>'; // 20-Dec-2013
var strdate=dtsheet.split("-");
var sheetdate =new Date(strdate[2] +"/"+ changemonth(strdate[1]) +"/"+ strdate[0]);
document.getElementById('id of generated input here').value = sheetdate;
I found my own solution. to set date for a c1WebdateEdit control, use the following code
var strdate=dtsheet.split("-");
var sheetdate =new Date(strdate[2] +"/"+ strdate[1] +"/"+ strdate[0]);
<%=dtpstartdate.ClientObjectID%>.set_Value(sheetdate);
to get the date,
var dt=<%=dtpstartdate.ClientObjectID%>.get_Value();
Related
The code snippet below is part of a larger script that collects user input from an HTML file and store these user input into my Google sheet. The type of input fields from the line
formObject.firmenp all the way to the line formObject.zielplanung in my HTML file is date and have each their own specific ID. I want to get these dates in format day/month/year into my sheet.
Any idea or recommendation how to achieve that?
Thank you so much in advance for your help :).
function getFormValues(formObject){
if(formObject.RecId && checkID(formObject.RecId)){
var values = [[formObject.RecId.toString(),
formObject.name,
formObject.unternehmen,
formObject.rufnummer,
formObject.email,
formObject.firmenp,
formObject.onboarding,
formObject.selbsttraining,
formObject.crmm,
formObject.tblock1,
formObject.fdtblock,
formObject.wochentraining,
formObject.zielplanung,
formObject.changestatus]];
}else{
var values = [[new Date().getTime().toString(),
formObject.name,
formObject.unternehmen,
formObject.rufnummer,
formObject.email,
formObject.firmenp,
formObject.onboarding,
formObject.selbsttraining,
formObject.crmm,
formObject.tblock1,
formObject.fdtblock,
formObject.wochentraining,
formObject.zielplanung,
formObject.changestatus]];
}
return values;
}
You can make a function like the below and convert all your data using it. Use this function on your script page.
//2021-11-05
var getDate = document.getElementById("date").value;
console.log("Inputted data: " + getDate);
function getNewDateFormat(value){
var dateValue = new Date(value);
var monthPart = dateValue.getMonth() + 1;
var dayPart = dateValue.getDate();
var yearPart = dateValue.getFullYear();
var newFormat = dayPart + "/" + monthPart + "/" + yearPart;
return newFormat
}
console.log("Expected data: " + getNewDateFormat(getDate));
//dummy input
<input type="text" id="date" value="2021-11-05" />
I have the following code in my jsp. I use JSTL ${scheduledRideEndTime} to retrieve the data.
<script>
var timeto2 = ${scheduledRideEndTime};
var hours3 = moment(timeto2).format("hh:mm a")
document.write(hours3);
</script>
If I hit Control Shift F on eclipse the formatting changes to
<script>
var timeto2 = $
{
scheduledRideEndTime
};
var hours3 = moment(timeto2).format("hh:mm a")
document.write(hours3);
</script>
I then get syntax errors in my view. If I redo the code to "${scheduledRideEndTime}"; the Control Shift F does not reformat the code, but view prints Invalid date.
What am I missing here ? I want to be able to reformat code.
Try this:
<script>
var timeto2 = parseInt("${scheduledRideEndTime}");
var hours3 = moment(timeto2).format("hh:mm a")
document.write(hours3);
</script>
I am trying to reset value of rich:calender input box via java script but couldnt do it any way at all. the UI of my form (snippet only) is...
<rich:calendar id="startDate" datePattern="dd MMM yyyy" value="#{classBean.startDate}" popup="true" onchanged="calcDuration();">
</rich:calendar>
the java script is
function calcDuration()
{
sdate =$('frm_course:startDate').component.getSelectedDateString("dd MMM
yyyy");
var currentdate = new Date();
var sdatecmp = new Date(sdate);
if(sdatecmp > currentdate)
{
alert('The Start Date is Greater than today!');
$('frm_viewCourseDetail:startDate').component.value = ""; // 1
document.getElementById('frm_course:startDate').value =""; // 2
}
}
None of the lines 1 and 2 resets the richcalender's value. Help is required here. thanks.
The calendar (and other components) is backed by a JavaScript object which has the methods you need.
Use either #{rich:component('startDate')} or RichFaces.$('startDate') to get a reference to that object and then call resetValue().
For other methods check the docs
I'm trying to get three different dynamic timezone clocks on my site. i've got the following js code which i found on this site (saved as myClocks.js and included on the header of my html site):
var clock1 = new Date();
var clock2 = new Date();
var clock3 = new Date();
clock2.setHours(clock2.getHours() + 3);
clock3.setHours(clock3.getHours() - 5);
clock1.getUTCHours();
clock1.getUTCMinutes();
clock1.getUTCSeconds();
clock2.getUTCHours();
clock2.getUTCMinutes();
clock2.getUTCSeconds();
clock3.getUTCHours();
clock3.getUTCMinutes();
clock3.getUTCSeconds();
How do I code the "display" to show it anywhere I want on my HTML page? For example as an id called clocks, to look like the following:
New York: 02:12:02 Paris: 17:01:24 Moscow: 22:23:42
Many thanks in advance.
<html><head></head><body>
<script language="javascript">
ourDate = new Date();
document.write("The time and date at your computer's location is: "
+ ourDate.toLocaleString()
+ ".<br/>");
document.write("The time zone offset between local time and GMT is "
+ ourDate.getTimezoneOffset()
+ " minutes.<br/>");
document.write("The time and date (GMT) is: "
+ ourDate.toGMTString()
+ ".<br/>");
</script>
</body></html>
innerHTML is what you need. Try something like:
window.onload = function(){ // It is important to wait till DOM is ready!
var clocks_str = clock3.getUTCHours()+" "+ clock3.getUTCMinutes()+" "+clock3.getUTCSeconds();
document.getElementById("clocks").innerHTML = clocks_str ;
}
And if you want it dynamic , use setInterval method , like this:
var clocks_interval;
var clocks_box;
window.onload = startClocks;
function startClocks(){
clocks_box = document.getElementById("clocks");
clocks_interval = setInterval(updateClocks , 1000); // 1000 means 1 second
}
function updateClocks (){
var clocks_str = clock3.getUTCHours()+" "+ clock3.getUTCMinutes()+" "+clock3.getUTCSeconds();
clocks_box.innerHTML = clocks_str ;
}
You can create a div or other HTML and use "innerHTML".
document.getElementById("clocks").innerHTML = clock1.getUTCHours();
Example:i am assigning this in .cs page
HiddenField hdnCharacter = new HiddenField();
HiddenField hdnMaxCharsError = new HiddenField();
Label lblMaxChrs = new Label();
lblMaxChrs.ID = "lblMaxchrs";
hdnMaxCharsError .ID = "hdnMaxCharsError ";
hdnCharater.ID = "hdnCharater";
How to get his ID and values using javascript in.js file i am trying to do custom control.so i dont have any page to add in aspcontrol. TR
use this way :
var id1=document.getElementById('<%= lblMaxchrs.ClientID %>');
var id2=document.getElementById('<%= hdnMaxCharsError.ClientID %>');
var id3=document.getElementById('<%= hdnCharater.ClientID %>');
even while you write the asp code. While rendering in the HTML format the field would be hidden but would be present in the page. you can use :-
var id1=document.getElementById('lblMaxchrs');
var id2=document.getElementById('hdnMaxCharsError');
var id3=document.getElementById('hdnCharater');
And in order to retrieve the values of each indevidual you can use :-
var text1=id1.textContent;
var text2=id2.textContent;
var text3=id3.textContent;