I want to try and print ".00" after the variables cache.todayHigh and cache.todayLow are whole numbers.
if (ddimgtooltip.showTips) {
// update tooltip
tip = 'High ' + strings.baro_info + ': ' + cache.todayHigh + ' ' + data.pressunit + ' ' + strings.at + ' ' + data.TpressTH +
' <br> ' + strings.minimum_info + ' ' + strings.baro_info + ': ' + cache.todayLow + ' ' + data.pressunit + ' ' + strings.at + ' ' + data.TpressTL;
if (cache.trendVal !== -9999) {
tip += '<br>' + strings.baro_trend_info + ': ' + baroTrend(cache.trendVal, data.pressunit, true) + ' ' +
(cache.trendValRnd > 0 ? '' : '') + cache.trendValRnd + ' ' + data.pressunit + '/hr';
}
$('#imgtip5_txt').html(tip);
}
e.g. 1017 hPa to 1017.00 hPa.
Is this possible?
Thanks,
William
Try this,
var yvalue = '1702 hpa';
var num = yvalue.replace(/[^0-9]+/ig,"");
value = Number(num).toFixed(2);
var fvalue= value +' '+yvalue.split(' ')[1]
console.log(fvalue);
Related
The line in question is...
if(listContent[Source].properties === ""
I need it to check if the "Source" key has any value. It's currently not outputting anything. What is proper syntax for this?
Here is the full code:
if (visibleFeatures) {
var uniqueFeatures = getUniqueFeatures(visibleFeatures, "arrayIndex");
for (var i = 0; i < uniqueFeatures.length; i++) {
if (listContent[Source].properties === "") {
listContent += '<div class="dealer"><h3>' + uniqueFeatures[i].properties.Name + '</h3><p class="address">' + uniqueFeatures[i].properties.Address + '<br>' + uniqueFeatures[i].properties.City + ', ' + uniqueFeatures[i].properties.State + ' ' + uniqueFeatures[i].properties.Zip + '</p><p class="phone">' + uniqueFeatures[i].properties.Phone + '</p></div>';
} else {
listContent += '<div class="dealer"><h3>' + uniqueFeatures[i].properties.Name + '</h3><p class="address">' + uniqueFeatures[i].properties.Address + '<br>' + uniqueFeatures[i].properties.City + ', ' + uniqueFeatures[i].properties.State + ' ' + uniqueFeatures[i].properties.Zip + '</p><p class="phone">' + uniqueFeatures[i].properties.Phone + '</p><p class="bl-map-link">' + uniqueFeatures[i].properties.Source + '</p></div>';
}
}
Thank you guys so much for all the help. I was able to figure out my error.
!!uniqueFeatures[i].properties.Source
The !! is what made the difference. I'm still researching why this works and why this doesn't if (strValue === "").
I'm trying to delete an item using the EWS MoveItem XML request. I'm sending this request to the makeEwsRequestAsync function:
function getMoveItemRequest(id, changeKey) {
var result =
'<?xml version="1.0" encoding="utf-8"?>' +
'<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:t="https://schemas.microsoft.com/exchange/services/2006/types">' +
'<soap:Header>' +
'<RequestServerVersion Version="Exchange2013" xmlns="http://schemas.microsoft.com/exchange/services/2006/types" soap:mustUnderstand="0" />' +
'</soap:Header>' +
'<soap:Body>' +
'<MoveItem xmlns="https://schemas.microsoft.com/exchange/services/2006/messages" xmlns:t="https://schemas.microsoft.com/exchange/services/2006/types">' +
'<ToFolderId>' +
'<t:DistinguishedFolderId Id="deleteditems" />' +
'</ToFolderId>' +
'<ItemIds>' +
'<t:ItemId Id="' + id + '" ChangeKey="' + changeKey + '" />' +
'</ItemIds>' +
'</MoveItem>' +
'</soap:Body>' +
'</soap:Envelope>';
return result;
}
I'm getting the item id from the message like this:
Office.context.mailbox.item.itemId
I'm getting changekey like this:
var mailbox = Office.context.mailbox;
var soapToGetItemData = getItemDataRequest(mailbox.item.itemId);
Office.context.mailbox.makeEwsRequestAsync(soapToGetItemData, function(result) {
var response = $.parseXML(result.value);
var responseString = result.value;
// TODO: May want to reconsider the logic for getting the ChangeKey
var indexOfChangeKey = responseString.indexOf("ChangeKey=\"");
var substringAfterChangeKey = responseString.substring(indexOfChangeKey + 11);
var indexOfQuotes = substringAfterChangeKey.indexOf("\"");
var changeKey = substringAfterChangeKey.substring(0, indexOfQuotes);
Here is the getItemDataRequest function:
function getItemDataRequest(itemId) {
var soapToGetItemData = '<?xml version="1.0" encoding="utf-8"?>' +
'<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"' +
' xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages"' +
' xmlns:xsd="http://www.w3.org/2001/XMLSchema"' +
' xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"' +
' xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">' +
' <soap:Header>' +
' <RequestServerVersion Version="Exchange2013" xmlns="http://schemas.microsoft.com/exchange/services/2006/types" soap:mustUnderstand="0" />' +
' </soap:Header>' +
' <soap:Body>' +
' <GetItem' +
' xmlns="http://schemas.microsoft.com/exchange/services/2006/messages"' +
' xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">' +
' <ItemShape>' +
' <t:BaseShape>IdOnly</t:BaseShape>' +
' <t:AdditionalProperties>' +
' <t:FieldURI FieldURI="item:Attachments" /> ' +
' </t:AdditionalProperties> ' +
' </ItemShape>' +
' <ItemIds>' +
' <t:ItemId Id="' + itemId + '"/>' +
' </ItemIds>' +
' </GetItem>' +
' </soap:Body>' +
'</soap:Envelope>';
return soapToGetItemData;
}
Yet, I'm getting an invalid response from this (the XML that is returned has "<faultstring xml:lang="en-US">The request is invalid." in it.)
Any ideas what's going on?
Thanks!
Needed to use http instead of https in the request.
function getMoveItemRequest(id, changeKey) {
var result =
'<?xml version="1.0" encoding="utf-8"?> ' +
'<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ' +
'xmlns:xsd="http://www.w3.org/2001/XMLSchema" ' +
'xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" ' +
'xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types"> ' +
'<soap:Header> ' +
'<t:RequestServerVersion Version="Exchange2013" xmlns="http://schemas.microsoft.com/exchange/services/2006/types" soap:mustUnderstand="0" /> ' +
'</soap:Header> ' +
'<soap:Body> ' +
'<MoveItem xmlns="http://schemas.microsoft.com/exchange/services/2006/messages" ' +
'xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types"> ' +
'<ToFolderId> ' +
'<t:DistinguishedFolderId Id="deleteditems"/> ' +
'</ToFolderId> ' +
'<ItemIds> ' +
'<t:ItemId Id="' + id + '" ChangeKey="' + changeKey + '"/> ' +
'</ItemIds> ' +
'</MoveItem> ' +
'</soap:Body> ' +
'</soap:Envelope> ';
return result;
}
var query =
'SELECT '
+ prefix + 'threads.tid as _tid, '
+ prefix + 'threads.fid as _cid, '
+ prefix + 'threads.firstpost as _pid, '
+ prefix + 'threads.views as _viewcount, '
+ prefix + 'threads.subject as _title, '
+ prefix + 'threads.dateline as _timestamp, '
+ prefix + 'threads.sticky as _pinned, '
+ prefix + 'posts.uid as _uid, '
+ prefix + 'posts.tid as _post_tid, '
+ prefix + 'posts.message as _content, '
+ 'IF(filetype like "image%", CONCAT("/uploads/files/MyBBAttachment/", attachname), NULL) as _images, '
+ 'IF(filetype like "image%", GROUP_CONCAT(filename SEPARATOR ","), NULL) as _imgnames, '
+ 'IF(filetype not like "image%", CONCAT("/uploads/files/MyBBAttachment/", attachname), NULL) as _attachments, '
+ 'IF(filetype not like "image%", GROUP_CONCAT(filename SEPARATOR ","), NULL) as _attachnames '
+ 'FROM ' + prefix + 'posts LEFT JOIN ' + prefix + 'attachments ON (' + prefix + 'posts.pid = ' + prefix + 'attachments.pid), ' + prefix + 'threads '
+ 'WHERE ' + prefix + 'threads.firstpost=' + prefix + 'posts.pid '
+ 'GROUP BY ' + prefix + 'posts.pid'
+ (start >= 0 && limit >= 0 ? 'LIMIT ' + start + ',' + limit : '');
Above query doesn't work in Node.js, I get following error:
{ Error: ER_PARSE_ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '0,600000' at line 1
But when I run similar thing in PHPMyAdmin, it works:
SELECT mybb_threads.tid as _tid, mybb_threads.fid as _cid, mybb_threads.firstpost as _pid, mybb_threads.views as _viewcount, mybb_threads.subject as _title, mybb_threads.dateline as _timestamp, mybb_threads.sticky as _pinned, mybb_posts.uid as _uid, mybb_posts.tid as _post_tid, mybb_posts.message as _content
FROM mybb_posts LEFT JOIN mybb_attachments ON mybb_posts.pid = mybb_attachments.pid, mybb_threads
where mybb_threads.firstpost=mybb_posts.pid
group by mybb_posts.pid
LIMIT 0, 100
How do I make var query work?
You're missing a whitespace before the limit keyword:
+ (start >= 0 && limit >= 0 ? ' LIMIT ' + start + ',' + limit : '');
// Here -----------------------^
i am having issue with assigning the variable into the URL
This is the code
var value = i+1;
var customPopup = 'Latitude: ' + data.Table[i].Latitude + '</br>Longitude: ' + data.Table[i].Longitude
+ '</br>Station: ' + data.Table[i].StationID + ' </br>Box: ' + data.Table[i].BoxID + '</br>Timestamp: ' + data.Table[i].LocationSend + "<br><a target='_blank' href='/Home/History?DeviceID= ' style='color: #000000'>Click Here For Location History</a></br>";
String literals might help (using backticks ``):
var value = i+1;
var customPopup = 'Latitude: ' + data.Table[i].Latitude +
'<br/>Longitude: ' + data.Table[i].Longitude +
'<br/>Station: ' + data.Table[i].StationID +
'<br/>Box: ' + data.Table[i].BoxID +
'<br/>Timestamp: ' + data.Table[i].LocationSend +
`<br/><a target='_blank' href='/Home/History?DeviceID=${value}' style='color: #000000'>Click Here For Location History</a><br/>`;
I'm using firebase to get this data,
I'd like to add href tags to message.userName output
$('#winners').text('Winner:' + ' ' + message.userName + ' ' + ' '+ 'score:' + ' ' + message.score + ' ' + ' '+ 'Start time:' + ' ' + message.startTime + ' ' + ' '+ 'End time:' + '' + message.endTime );
I've tried
$('#winners').text('Winner:' + ' ' + '<a href=\"scoreTracker.php?id='+message.userID +'\"> + ' message.userName + ' ' + ' '+ 'score:' + ' ' + message.score + ' ' + ' '+ 'Start time:'
+ ' ' + message.startTime + ' ' + ' '+ 'End time:' + '' + message.endTime + '<\a>' );
To avoid XSS attacks (among other weird problems), append an anchor element and set its text. This means you don't have to worry about escaping anything.
$('#winners').append([
'Winner: ',
$('<a>')
.attr('href', 'scoreTracker.php?id=' + encodeURIComponent(message.userId))
.text(
message.userName + ' score: ' + message.score + ' Start time: ' + message.startTime + ' End time: ' + message.endTime
)
]);
If your HTML gets much more complicated, might I suggest a JavaScript template engine? I use Swig for most projects, but there are many choices.
you have to use append() , or html()
$('#winners').append('Winner:' + ' ' + message.userName + ' ' + ' '+ 'score:' + ' ' + message.score + ' ' + ' '+ 'Start time:' + ' ' + message.startTime + ' ' + ' '+ 'End time:' + '' + message.endTime );
this may help you to understand better :
http://api.jquery.com/category/manipulation/dom-insertion-inside/
Both #Brad and #ProllyGeek are correct -- but #Brad's solution is best given the potential risk of XSS attacks. Here is his code, just cleaned up a bit for better readability. :)
$('#winners').append([
'Winner: ',
$('<a />')
.attr('href', 'scoreTracker.php?id=' + encodeURIComponent(message.userId)
.text(message.userName + ' score: ' + message.score + ' Start time: ' + message.startTime + ' End time: ' + message.endTime)
]);
Hope this helps!