Javascript copy text script not working properly? [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 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')

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.

Missing parenthesis before function parameters [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 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)

use if condition in javascript [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 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.

Filter a table by Javascript [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 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>

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