Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 9 years ago.
Improve this question
Is there a JavaScript library or easily working with cookies?
vanilla javascript FTW
/*********************************************************
gets the value of a cookie
**********************************************************/
document.getCookie = function(sName)
{
sName = sName.toLowerCase();
var oCrumbles = document.cookie.split(';');
for(var i=0; i<oCrumbles.length;i++)
{
var oPair= oCrumbles[i].split('=');
var sKey = decodeURIComponent(oPair[0].trim().toLowerCase());
var sValue = oPair.length>1?oPair[1]:'';
if(sKey == sName)
return decodeURIComponent(sValue);
}
return '';
}
/*********************************************************
sets the value of a cookie
**********************************************************/
document.setCookie = function(sName,sValue)
{
var oDate = new Date();
oDate.setYear(oDate.getFullYear()+1);
var sCookie = encodeURIComponent(sName) + '=' + encodeURIComponent(sValue) + ';expires=' + oDate.toGMTString() + ';path=/';
document.cookie= sCookie;
}
/*********************************************************
removes the value of a cookie
**********************************************************/
document.clearCookie = function(sName)
{
setCookie(sName,'');
}
Related
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 7 years ago.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Improve this question
I'm getting an error with my javascript: "missing ; before statement".
I'm trying to read in a date, add 6 months onto the date if it meets a certain criteria ( joiner type in this case) and if not just return that date.
I can't see whats wrong here, it must be something small, any ideas??
Thanks!
function checkenddate(Par) {
var array = Par.split("!!");
var usermskey = array[0];
var date = array[1];
var joinertype = array[2];
saprep = UserFunc.uGetConstant("glb.REPOSITORY_ECC");
attr1 = "Z_VALIDTO" + saprep;
uWarning("Attribute: " + attr1);
if (date == null && joinertype.equals("Contractor"))
{
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Calender c = Calender.getInstance();
c.setTime(sdf.parse(date));
c.add(Calender.MONTH, 6);
enddate = sdf.format(c.getTime());
uWarning("End Date:" + enddate);
OutString = uIS_SetValue(usermskey, 0, attr1, enddate);
return enddate;
} else {
OutString = uIS_SetValue(usermskey, 0, attr1, date);
return date;
}
}
Thats not valid javascript. You can't have typed variables such as SimpleDateFormat sdf = new blah(). Change your types to var and it will work as expected.
var sdf = new SimpleDateFormat("yyyy-MM-dd");
var c = Calender.getInstance();
This is not how you declare a JS variable:
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
You need this instead:
var sdf = new SimpleDateFormat("yyyy-MM-dd");
I would recommend using one of the linting tools online (e.g. JSHint or JSLint) to help track down these issues - very handy.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
Introduce the problem before you post any code:
I have a simple JavaScript code and it's giving me an unexpected token error. It's code that I'm trying to convert from PHP to JavaScript for use in a Phonegap application.
Specifically it is the line that declares the $ex_data variable. And it says the unexpected token is the section between the $system and $galaxy variables.
Code
for ($galaxy = 1; $galaxy < 21; $galaxy++){
for ($system = 1; $system < 601; $system++){
var $ex_data = '{"planet_id":-1,"sid":'.$system.',"language":"en","gid":'.$galaxy.'}';
var $url = "http://54.193.106.113/ING004/android1/WebServer/Web/sogame/newControl/nmUniverse/getUniverse?sign=".toUpperCase($sign);
}
}
CLEAR QUESTION:
How do I fix the line so that it is valid?
You are confusing PHP concatenation with JavaScript (C) concatenation.
for ($galaxy = 1; $galaxy < 21; $galaxy++) {
for ($system = 1; $system < 601; $system++) {
var $ex_data = '{"planet_id":-1,"sid":'
. $system . ',"language":"en","gid":' . $galaxy.'}';
var $url = "http://54.193.106.113/ING004/android1/WebServer/Web/sogame/newControl/nmUniverse/getUniverse?sign="
.toUpperCase($sign);
}
}
Change the ".s" to "+s".
var $ex_data = '{"planet_id":-1,"sid":'
+ $system + ',"language":"en","gid":' + $galaxy + '}';
or alternatively
var $ex_data = JSON.stringify({
"planet_id" : -1,
"sid" : $system,
"language" :"en",
"gid" : $galaxy
});
Also, as pointed out below, change .toUpperCase($sign); -> + $sign.toUpperCase();
var $ex_data = '{"planet_id":-1,"sid":' + $system + ',"language":"en","gid":' + $galaxy +'}';
var $url = "http://54.193.106.113/ING004/android1/WebServer/Web/sogame/newControl/nmUniverse/getUniverse?sign=" + $sign.toUpperCase();
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I have this code that does not work:
kw _class = _keyword1;
var text = $("'input." + kw_class + "[type=text]'").val();
var val = $("'input." + kw_class + "[type=hidden]'").val();
Firefox console comes out with this:
`Syntax error, unrecognized expression: 'input._keyword1[type=text]'
I have tried at least three combos of this that are not working that I found from other questions.
Yes because you have ' ' inside of the selector. It should be:
var text = $("input." + kw_class + "[type=text]").val();
var val = $("input." + kw_class + "[type=hidden]").val();
you have extra '' in the selector
var text = $('input.' + kw_class + '[type=text]').val();
var val = $('input.' + kw_class + '[type=hidden]').val();
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I'm new to query/javascript and having a problem with the following code to calculate a gross value and tax amount based
on the net amount the user enters. The user will enter a double amount and the gross and vat amounts are also defined as doubles.
Can anyone help? I get an error: "Uncaught SyntaxError: Unexpected number" when i try running the following code.
$('#netPayment').change(calcLowerVatRateAndGrossAmount);
/* $('#netPayment').change(function(){
calcLowerVatRateAndGrossAmount();
}); */
});
function calcVatRateAndGrossAmount(){
var netPayment = parseFloat($('#netPayment').val());
var vatAmount = 00.0;
var VatRate = 20.0;
var grossPayment = 0.00;
var totalPaymentAmount = 0.00;
if (netPayment !== '') {
vatAmount = (netPayment * VatRate) / 100;
grossPayment = (netPayment - vatAmount);
$('#vatAmount').val(parseFloat(vatAmount.data).toFixed(2));
$('#grossPayment').val(parseFloat(grossPayment.data).toFixed(2));
} else {
$('#vatAmount').val(vatAmount.amountNull);
$('#grossPayment').val(grossPayment.amountNull);
}
};
So you calculate a number here
vatAmount = (netPayment * VatRate) / 100;
And in here, you treat vatAmount as an object that has a key data
$('#vatAmount').val(parseFloat(vatAmount.data).toFixed(2));
You should just be using the variable. A simple test
console.log("variable itself: ", vatAmount);
console.log("key data: ", vatAmount.data);
So you would need to just do
$('#vatAmount').val(vatAmount.toFixed(2));
$('#grossPayment').val(grossPayment.toFixed(2));
You do the same thing with grossPayment and you reference some other property vatAmount.amountNull
$('#vatAmount').val(vatAmount.amountNull);
$('#grossPayment').val(grossPayment.amountNull);
should be
$('#vatAmount').val(""); //or any error message
$('#grossPayment').val("");
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions must demonstrate a minimal understanding of the problem being solved. Tell us what you've tried to do, why it didn't work, and how it should work. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I will try to keep this short; I am trying to scrape information from exactly this website : http://eu.battle.net/wow/en/character/uldaman/Dus/statistic#21:152
That list includes an item "Highest 2 man personal rating" followed by a number. The number is what I'm looking for. Where exactly is the number stored and how can I obtain it?
Thanks in advance.
I am considering you are using jQuery:
$('#cat-152 dt').filter(function() { return $(this).text() == "Highest 2 man personal rating" }).siblings('dd').text()
var http = require('http');
var options = {
host: 'eu.battle.net',
path: '/wow/en/character/uldaman/Dus/statistic/152'
};
var count = 0;
http.get(options, function(res) {
var data = "";
res.on('data', function (chunk) {
data += chunk;
});
res.on('end', function(){
var d = data;
var payload = d.toString();
var finder = "<dt>Highest 2 man team rating</dt><dd>";
var indexOfHighest2Man = payload.indexOf(finder);
var indexOfClosingDD = payload.indexOf("</dd>", indexOfHighest2Man);
var count = payload.substr(indexOfHighest2Man, indexOfClosingDD - indexOfHighest2Man);
count = count.replace(/\s/g, "");
count = count.replace("<dt>Highest2manteamrating</dt><dd>", "");
//***************** Here is the answer *******************
console.log('Highest 2 man rating ',count);
//********************************************************
})
}).on('error', function(e) {
console.log('ERROR: ' + e.message);
});