Codes block has an syntax error [closed] - javascript

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 6 years ago.
Improve this question
For some reason this code block is giving an error and i can't figure out what is the matter with it. Any help is appreciated.
function Submit(e) {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var s = e.getActiveSheet();
var range = e.getActiveRange();
var cell = range.getActiveCell();
var cellValue = ss.getActiveCell(9,17);
if( cellValue == <0 ){
var report = s.getDataRange("A101:Q106");
var numColumns = s.getLastColumn();
var targetsheet = ss.getSheetByName("Report");
var date = s.getSheetName();
var target = targetsheet.getRange(targetsheet.getLastColumn() + 1 , 1);
e.getRange(report).copyTo(target);
}
}

This is the line that is causing the syntax error:
if( cellValue == <0 ){
If you just want to know if cellValue is equal to 0, then you should change it to:
if( cellValue == 0 ){
If you're trying to see if cellValue is less than 0, then the proper way is:
if( cellValue < 0 ){
See http://devdocs.io/javascript/operators/comparison_operators for more information.

Related

Split cookies from page [closed]

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 2 months ago.
Improve this question
I was doing some coding today, but I got an error:
Cannot read properties of undefined (reading 'split')
at getCookie ((index):38:49)
at (index):47:31
My code (begins at line 36, ends at 43):
var cookieArray = document.cookie.split(";");
for (var i = 0; i < cookieArray.length; i++) {
var cookiePair = cookieArray[1].split("=");
if(name == cookiePair[0].trim()) {
return decodeURIComponent(cookiePair[1])
}
}
Btw, I've read that you can only split a string, but this is a string right?
You should put i instead of 1:
for (var i = 0; i < cookieArray.length; i++) {
var cookiePair = cookieArray[i].split("=");
if(name== cookiePair[0].trim()) {
return decodeURIComponent(cookiePair[i])
}
}
Because the first time it iterates the array cookieArray[1] my be undefind.

How to take users input, modify it, then display it in JQuery? [closed]

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 6 years ago.
Improve this question
I am trying to make a unit converter, I will have the user enter a numeric value in a text box, select a unit type(lbs, g, oz etc...) from a select element, then do some simple multiplication to get the conversion, then finally, the part I am having trouble with, display the conversion result in a designated area. I can not get the text to change to the conversion result. I only have one conversion coded so far and that is pounds to grams, because I want to be able to display the text before I code the rest of them. Thank you and any input helps!
var main = function() {
var rslt = $('#result').val;
var num = $('#nmbr').val();
var inpt = $('#slct1').val();
var outpt = $('#slct2').val();
var bttn = $('.sbs');
$('.sbs').click(function(){
if(inpt == 'pounds'){
if(outpt == 'grams') {
var pGrams = num * 453.592;
$('#result').text(pGrams);
}
}
})
}
$(document).ready(main);
full code: https://jsfiddle.net/drzb6frk/
Try this javascript code:
var main = function() {
var bttn = $('.sbs');
$('.sbs').click(function(){
var rslt = $('#result').val;
var num = $('#nmbr').val();
var inpt = $('#slct1').val();
var outpt = $('#slct2').val();
if(inpt == 'pounds'){
if(outpt == 'grams') {
var pGrams = num * 453.592;
$('#result').text(pGrams);
}
}
})
}
$(document).ready(main);

Missing ) after arguement list. (line 6 file "code") [closed]

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'm new to coding and a got this pre set code to use within a spreadsheet for a google awesome table, and I keep getting this error.
Missing ) after argument list. (line 6, file "Code)
Here is my code:
var formURL = 'https://docs.google.com/a/waitrose.co.uk/forms/d/11-z44oW1ixP1tShkwjrBpa0DptOA2IinU5MCCkUvf0o/viewform';
var sheetName = 'Form responses 1';
var columnIndex = 5;
function getEditResponseUrls(){
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(Form responses 1);
var data = sheet.getDataRange().getValues();
var form = FormApp.openByUrl(formURL);
for(var i = 2; i < data.length; i++) {
if(data[i][0] != '' && (data[i][columnIndex-1] == '' || !data[i][columnIndex-1])) {
var timestamp = data[i][0];
var formSubmitted = form.getResponses(timestamp);
if(formSubmitted.length < 1) continue;
var editResponseUrl = formSubmitted[0].getEditResponseUrl();
sheet.getRange(i+1, columnIndex).setValue('<div style="width:100px">Edit entry</div>');
}
}
}
Looks like you are missing a pair of quotes on line 6:
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(Form responses 1);
should be
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Form responses 1");

Javascript - Passing from a DOM element to array [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 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
Hello and thank you for your time.
Here is the code :
<script>
var names = document.getElementsByClassName('xx');
var ar = [];
for (var i = 0, c = names.length ; i < c ; i++) {
ar[i] = names[i].innerHTML;
alert(ar[i]);// the results are : undefined
}
</script>`
I've tried to use the method tostring, or to push the results into the array but without success.
Thanks
Your main issue seems to be fixed. Make sure the DOM has been loaded before you try to run your code, and there is no need for two variables in your loop. Simplify it like below:
window.onload = function () {
var names = document.getElementsByClassName('xx');
var ar = [];
for (var i = 0 ; i < names.length ; i++) {
ar[i] = names[i].innerHTML;
alert(ar[i]);
}
};
Fiddle
ar.length equals 0, because you just declare the array, but dont put anything into it. I think what you wanted to do is the following:
var names = document.getElementsByClassName('xx');
var ar = [];
for (var i = 0 ; i < names.length ; i++) {
ar[i] = names[i].innerHTML;
alert(ar[i]);
}

Complex jQuery if statements including operators [closed]

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 would like to show a different div depending on what class my 3 span elems contain.
If all span hasClass up or up1 the code would show a div with class allUp . If it hasClass up up1 and down then it would show a div with class twoUp.
I wrote the following, but of course it doesn't work.
var $line1 = $(".line1")
var $line2 = $(".line2")
var $line3 = $(".line3")
if($line1.hasClass("up") || $line1.hasClass("up1")
&& $line2.hasClass("up") || $line2.hasClass("up1")
&& $line3.hasClass("up") || $line3.hasClass("up1")) {
$(".allUp").show();
}
else if ($line1.hasClass("up") || $line1.hasClass("up1")
&& $line2.hasClass("up") || $line2.hasClass("up1")
&& $line3.hasClass("down") || $line3.hasClass("down1")) {
$(".twoUp").show();
}
else if ($line1.hasClass("up") || $line1.hasClass("up1")
&& $line2.hasClass("down") || $line2.hasClass("down1")
&& $line3.hasClass("down") || $line3.hasClass("down1")) {
$(".oneUp").show();
}
else {
$(".down").show();
}
think I've fixed the syntax errors
This should work, and tidies your logic up quite a lot. I've also updated it with your class-names for lines 1, 2 and 3.
var $lines = $('.line1, .line2, .line3'),
numUp = $lines.filter('.up, .up1').length,
classes = [ 'allDown', 'oneUp', 'twoUp', 'allUp' ];
$( '.' + classes[numUp] ).show();
the var $('line') = line should be var line = $('line'), and elseif should be else if

Categories

Resources