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 years ago.
Improve this question
I want to use if in javascript. I used the if condition as I mentioned below. But is incorrect. why is it wrong. and how can I solve it?
var fixHelperModified = function(e, tr) {
var $originals = tr.children();
var $helper = tr.clone();
$helper.children().each(function(index) {
$(this).width($originals.eq(index).width())
});
return $helper;
},
if (window.confirm("Do you really want to update the order?")) {
updateIndex = function(e, ui) {
$('td.index', ui.item.parent()).each(function(i) {
$(this).html(i + 1);
});
};
}
$("#table tbody").sortable({
helper: fixHelperModified,
stop: updateIndex
}).disableSelection();
You have to delete the ',' in Line 8.
Related
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.
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 3 months ago.
Improve this question
I'm trying to update some old code for a customer but I keep receiving missing ( before function parameters in my log files.
function gmtToFloat(tc) {
timecode = tc.toString();
var hhd = parseFloat(timecode.slice(-6, -3));
var mmd = parseFloat(timecode.slice(-2)) / 60;
return (hhd + mmd);
}
var diff =
gmtToFloat({Data.Session.utc}) - gmtToFloat({Data.Session.ctc});
diff;
What am I doing wrong?
Here:
function gmtToFloat(tc) {
timecode = tc.toString();
var hhd = parseFloat(timecode.slice(-6, -3));
var mmd = parseFloat(timecode.slice(-2)) / 60;
return hhd + mmd;
}
var diff = gmtToFloat(Data.Session.utc) - gmtToFloat(Data.Session.ctc);
diff;
You have to change gmtToFloat({ Data.Session.utc }) to gmtToFloat(Data.Session.utc)
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I started with this code as part of a for loop:
var depthCat = "DMAD" + i.toString();
var tempDepth = document.getElementById("DMAD" + i.toString());
var depth = document.getElementById("DMAD" + i.toString()).value;
started thinking it was a little too verbose and slimmed it down to this:
var depth = document.getElementById("DMAD" + i.toString()).value;
my understanding of preventing injections and the like is limited, so I'm wondering if I've created any potential issues for myself?
Be careful, if no HTML element is found, then you will get an error
You should test if document.getElementById("DMAD" + i) is not null, or execute
var dmadElement = document.getElementById("DMAD" + i)
var depth = dmadElement ? dmadElement.value : null
or
var depth = null
try {
depth = document.getElementById("DMAD" + i).value
catch (e) {
// console.error(e)
}
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 7 years ago.
Improve this question
<script type="text/javascript">
function filterResults() {
var trTag = document.getElementsByTagName("tr");
for (var i = 0; i < trTag.length; i++) {
if (trTag[i].OuterHTML.includes(filterTXT.Value)) {
trTag.Style.Display = "none";
}
}
}
</script>
Firefox tells me: trTag[i].OuterHTML is undefined. I assume this is because OuterHTML does not exist? If so, what do I use instead?
JavaScript is a case-sensitive language.
JavaScript is case sensitive. It is common to start the name of a constructor with a capitalised letter, and the name of a function or variable with a lower-case letter (ref).
You might want to make these changes
outerHTML not OuterHTML (ref)
style not Style (ref)
display not Display (ref)
value not Value (ref)
in your script.
<script type="text/javascript">
function filterResults() {
var trTag = document.getElementsByTagName("tr");
for (var i = 0; i < trTag.length; i++) {
if (trTag[i].outerHTML.includes(filterTXT.value)) {
trTag.style.display = "none";
}
}
}
</script>
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 javascript for copying text but for some reason it isn't working and i for the life of me can't figure out what!
<script>
function copyText(field) {
var selectedText = document.selection;
if (selectedText.type = 'Text') {
var newRange = selectedText.createRange();
field.focus();
field.value = newRange.text;
} else {
alert('select a text in the page and then press this button');
}
}
</script>
if (selectedText.type = 'Text') {
should be
if (selectedText.type == 'Text') {
= is for setting
== is for comparing
You have a typo in your if conditional:
if (selectedText.type = 'Text')
should be:
if (selectedText.type == 'Text')