dateformat is divided and i get totally different value - javascript

i have a little javascript that should bring some values to change the link, but the problem is that date format is written like: dd/mm/year thus the day is divided by month then by year :) here is the function:
function show_sales(employee_id,start_date,finish_date)
{
var url_str = "#request.self#?fuseaction=objects2.popup_showsales_emp"
url_str = url_str + '&employee_id=' + employee_id;
url_str = url_str + '&start_date=' + start_date;
url_str = url_str + '&finish_date=' + finish_date;
AjaxPageLoad(url_str,'salesdiv_' + employee_id,1,'Yükleniyor');
}
as u can see i want to get the start date and finish date to change the link, but instead it counts the value )) so instead of getting: 02/01/2012 i get: 0.0009940357852882703 :) thank you all for the help!

i hope there is a prob in function call
function show_sales(1,'12/3/2008','15/5/2012');
make sure that date is formatted as string

I am not quite sure if I have understand you but this may help:
function show_sales(employee_id,start_date,finish_date)
{
var url_str = "#request.self#?fuseaction=objects2.popup_showsales_emp"
url_str = url_str + '&employee_id=' + encodeURIComponent(employee_id);
url_str = url_str + '&start_date=' + encodeURIComponent(start_date);
url_str = url_str + '&finish_date=' + encodeURIComponent(finish_date);
AjaxPageLoad(url_str,'salesdiv_' + employee_id,1,'Yükleniyor');
}

Related

Unable to display total using append

I am making a food delivery app. I would like that there would be a place whereby it would display the total. Right now, I am unable to display the total amount from multiplying quantity and price. It does not show up on the app.
And, there are no errors on the console too.
Javascript Code:
function _showorderResult(arr) {
var value1 = arr[0].price;
var value2 = arr[0].quantity;
for (var i = 0; i < arr.length; i++) {
result = value1 * value2;
htmlstring = "";
$("#itemimage").html("<img src='" + serverURL() + "/images/" +
arr[i].imagefile + "' width='200'>");
$("#price").html("Price" + ": " + " $" + arr[i].price);
$("#itemname").html("Item" + ":" + arr[i].itemName);
$("#quantity").html("Quanitiy" + ":" + arr[i].quantity);
$("result").append(htmlstring);
$("#requestedDateTime").html("To delivery by" + ":" + arr[i].requestedDateTime);
$("#deliveredDateTime").html("Delivered on" + ":" + arr[i].deliveredDateTime)
}
}
And, there are no errors on the console too.
There were plenty of errors in my console, but there are several mistakes here. The first is that your code is not runnable. Please consider making a minimal, verifiable example.
Next, you are misusing or not properly formatting the append(...) function. That's intended to append HTML elements, not string values.
As the comments suggest, you seem to have confused var result and $("result"). If you're not using the DOM selector, you probably don't want to jQuery-wrap your variables. The proper jQuery-wrap syntax would have been $(result) without the double quotes, but please don't do that either, it doesn't offer any benefit over just var result. htmlstring doesn't contain any actual HTML, so I've renamed it runningTotal instead and add it to the price * quantity. This must be initialized first or you'll get NaN.
Make sure to initialize your variables. To this point, there's some hard-coded indexes such as value1 = arr[0].price which make no sense in this pasted code. We can assume you left these here after troubleshooting. Please clean them up next time.
Finally, this is minor, but be consistent with your object names... e.g. imagefile versus imageFile. It doesn't matter which you choose so as long as you're consistent. This will help find typos down the road.
Here's a working example:
<html>
<img src="" id="itemimage">
<p id="price">Price: $0.00</p>
<p id="itemname">Item: None</p>
<p id="quantity">Quantity: None</p>
<p id="result">Running: None</p>
<p id="requestedDateTime">To delivery by: None</p>
<p id="deliveredDateTime">Delivered on: None</p>
<script>
var order = [{
price: 5,
quantity: 3,
itemName: 'Pizza',
imagefile: 'pizza.png',
requestedDateTime: '12:00',
deliveredDateTime: '12:30'
}];
/** Dummy function to allow code to run **/
var serverURL = function() { return ""; }
function _showorderResult(arr) {
// var value1 = arr[0].price;
// var value2 = arr[0].quantity;
var result;
var runningTotal = 0;
for (var i = 0; i < arr.length; i++) {
result = arr[i].price * arr[i].quantity;
runningTotal += result;
$("#itemimage").html("<img src='" + serverURL() + "/images/" + arr[i].imagefile + "' width='200'>");
$("#price").html("Price" + ": " + " $" + arr[i].price);
$("#itemname").html("Item" + ":" + arr[i].itemName);
$("#quantity").html("Quanitiy" + ":" + arr[i].quantity);
$("#result").html("Running" + ":" + runningTotal);
$("#requestedDateTime").html("To delivery by" + ":" + arr[i].requestedDateTime);
$("#deliveredDateTime").html("Delivered on" + ":" + arr[i].deliveredDateTime);
}
}
_showorderResult(order);
</script>
</html>

Excel Export getting error: Failed - Network Error on large exports

I'm using this code to export tables off of a web page.
This snippet of code works fine when I export tables of < 1000 rows or so, but when I try to export larger tables I get the error: Failed Network Error. This happens in chrome. It doesn't do anything in IE (surprise).
Is it a memory issue? Any ideas how I can export large tables without running into issues?
Thanks for any help
var dt = new Date();
var day = dt.getDate();
var month = dt.getMonth() + 1;
var year = dt.getFullYear();
var hour = dt.getHours();
var mins = dt.getMinutes();
var postfix = month + "." + day + "." + year + "_" + hour + "." + mins;
//creating a temporary HTML link element (they support setting file names)
var a = document.createElement('a');
//getting data from our div that contains the HTML table
var data_type = 'data:application/vnd.ms-excel';
var table_div = document.getElementById('datatable');
var table_html = table_div.outerHTML.replace(/ /g, '%20');
a.href = data_type + ', ' + table_html;
//setting the file name
a.download = 'MachineReport_' + postfix + '.xls';
//triggering the function
a.click();
//just in case, prevent default behaviour
e.preventDefault();
I had faced the same problem. This help me solved it. Please try replace:
a.href = data_type + ', ' + table_html;
With:
xData = new Blob([table_html], { type: 'text/csv' });
var xUrl = URL.createObjectURL(xData);
a.href = xUrl;
No answers, but after research it seems to be part of the 2meg limit Chrome imposes when trying to execute this script. I do not know of a work around.

Date format with javascript do not work in my classic asp page

I have this javascript function:
function montaDataSubstituicaoPrestador(dt_exclusao, periodo){
//var exclusao = dt_exclusao.setDate(dt_exclusao.getDate() + periodo);
//alert(dt_exclusao.setDate(dt_exclusao.getDate() + periodo));
alert(dt_exclusao);
alert(periodo);
dt_exclusao.setDate(dt_exclusao.getDate() + periodo);
alert(dt_exclusao);
}
Below this line dt_exclusao.setDate(dt_exclusao.getDate() + periodo); do not work nothing.
If I uncomment this line
//alert(dt_exclusao.setDate(dt_exclusao.getDate() + periodo));
the code after line do not work. Where is my issue?
This way do not work:
var dt_exclusao = '26/11/2015';
var periodo = 60;
var nova_data = new Date(dt_exclusao);
//alert(dt_exclusao.setDate(dt_exclusao.getDate() + periodo));
alert(nova_data);
alert(periodo);
nova_data.setDate(nova_data.getDate() + periodo);
alert(nova_data);
But, if I change the format date, it Works, this way.
var dt_exclusao = '2015-11-26T00:00:00';
var periodo = 60;
var nova_data = new Date(dt_exclusao);
//alert(dt_exclusao.setDate(dt_exclusao.getDate() + periodo));
alert(nova_data);
alert(periodo);
nova_data.setDate(nova_data.getDate() + periodo);
alert(nova_data);
But i receive the date in this format:
'dd/mm/yyyy'
`enter code here`i tryed:
Date.parse(), and
stringTodate() and nothing. How can I do to receive the date in one format and change to another?
I resolved this way:
function montaDataSubstituicaoPrestador(dt_exclusao, periodo){
var arrData = dt_exclusao.split('/');
var exclusaoFormatada = arrData[1] + '-' + arrData[0] + '-' + arrData[2];
var dias = parseInt(periodo);
var novaData = new Date(arrData[2], arrData[1] - 1, arrData[0]);
novaData.setDate(novaData.getDate() + dias);}
The problem was here:
dt_exclusao, but it was receiving a format not recognized. Thanks for all.

Need help on how to Parse a response from Wunderground API Forecast for 3 days using Json

I have succeeded in parsing a response from the Wunderground API and displaying a response for the "current" weather conditions of a state and certain city. This tells me the exact temp and current conditions outside at the time of the call.
I now need the ability and I am having trouble getting a 3 day forecasted response to work along with the current weather condition response I have.
My end result I want a 3 day forecasted result and all of those days to contain High and Low Temps for those days only.
Example:
Day 01 - Monday High / Low
Day 02 - Tuesday High / Low
Day 03 - Wednesday High / Low
Day 01 would technically be the current day it is.
Please if anyone can take a look at my script as of now and help add what is missing I would appreciate it.
Here is my JS
jQuery(document).ready(function($) {
/* Edit these variables */
var api = "2ea138a9dd52eabe";
var state = "TX";
var city = "Dallas";
$.ajax({
url: "http://api.wunderground.com/api/" + api + "/forecast/conditions/q/" + state + "/" + city + ".json",
dataType : "jsonp",
success : function(parsed_json) {
var icon_url_json = "http://icons.wxug.com/i/c/f/" + parsed_json['current_observation']['icon'] + ".gif";
var icon_json = '<img src ="' + icon_url_json + '" />';
var temp_json = parsed_json['current_observation']['temp_f'];
temp_json += "<span>°F</span>";
var condition_json = parsed_json['current_observation']['weather'];
var real_feel_json = "Feels Like " + parsed_json['current_observation']['feelslike_f'] + "°F";
var wind_json = 'Winds are ' + parsed_json['current_observation']['wind_string'];
var location_json = city + ', ' + state;
var forecastArray = parsed_json['forecast']['txt_forecast']['forecastday'];
if (forecastArray !== null) {
for (var i = 0; i < forecastArray.length; i++) {
if (forecastArray[i] !== null) {
//use can use this to assing directly to HTML element
console.log(forecastArray[i]['period']);
console.log(forecastArray[i]['title']);
console.log(forecastArray[i]['fcttext']);
}
}}
document.getElementById("weather-icon").innerHTML = icon_json;
document.getElementById("temp").innerHTML = temp_json;
document.getElementById("condition").innerHTML = condition_json;
document.getElementById("real-feel").innerHTML = real_feel_json;
document.getElementById("wind").innerHTML = wind_json;
document.getElementById("location").innerHTML = location_json;
}
});
});
I have also put this up here for people to look at it working as of now. http://jsfiddle.net/supasmo/9d5bh/2/
You can actually fetch for next 10 days http://jsfiddle.net/xxk7S/ Updated. Here is the Updated Code
for(var some in parsed_json.forecast.txt_forecast.forecastday){
console.log("*************");
$("#nxtDays").append("<b>"+parsed_json.forecast.txt_forecast.forecastday[some].title+" </b> <br />"+
parsed_json.forecast.txt_forecast.forecastday[some].fcttext+"<br />"); console.log(parsed_json.forecast.txt_forecast.forecastday[some].title);
}

Strange jQuery behaviour

I know that $("#SendingType").val(2) sets the value of the select to 2.
So, why does this goes to else??
$(function () {
$("#calculate").click(function () {
var result = $("#SendingType").val();
var day1 = eval(result) + 3;
var day2 = eval(result) + 10;
var day3 = eval(result) + 2;
if ($("#SendingType").val(2)) {
$("#result").text(day1 + " and " + day2 + " days.");
} else {
$("#result").text(day1 + " and " + day3 + " days.");
}
});
});
I am aware that this is not correct way to code if statement.
SOLVED: Thank you Jason and Juhana. The code does not go to else, I thought it would because the value of the select influences the if result. Always if but with different results because of the new select value.
FIDDLE
Looks to me like it runs the true branch regardless:
http://jsfiddle.net/tMwRV/
Which makes sense. You are setting the value to 2, not checking the value. The statement $("#SendingType").val(2) returns a jQuery object, which is "truthy".

Categories