jquery string not working inside $() [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 7 years ago.
Improve this question
I have the following jquery function. and i am calling it as below mentioned.
function hideSubArea(area, subArea) {
if ($('#cmdArea').val() == area) {
console.log('hide:' + subArea);
//$(":checkbox[value=peoplebulkinsert]").closest("label").hide();
$(":checkbox[value=subArea]").closest("label").hide();
}
}
And calling it as
hideSubArea('<?php echo CustomType::CF_PEOPLE ?>', '<?php echo CustomType::CF_SUB_PEOPLE_BULK_INSERT ?>');
this way its not working.
also this is not.
hideSubArea('people', 'peoplebulkinsert');
but it works when i directly use as
$(":checkbox[value=peoplebulkinsert]").closest("label").hide();
why this happens with jquery ?

subArea is a variable, not a string in this case. It needs to be concatenated. It should be -
$(":checkbox[value='" + subArea + "']")

Related

Javascript backgroundColor works on some computers, not on others? [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
This part of javascript code works on my home computer, but doesn't at work. Also, my colleague tested it and it doesn't work on her home computer?!
function klikNaX(x, y, z) {
var u = document.getElementById(z);
var u2;
u2 = u.style.backgroundColor;
document.getElementById("test").innerHTML = (z + " " + u2);
}
The problem seems to be with this part
u.style.backgroundColor;
Its not a problem of style.backgroundColor, instead please check if 'u' is a valid node and not undefined.
And try setting a color to u.style.backgroundColor = 'green'

Why does JavaScript get this comparison wrong? [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
This is happening on an angular application I'm building. If a user enters 80 into an HTML input, it always seems to get this comparison wrong.
var x = '80';
var y = 150.9800;
/* Returns incorrect answer */
if (parceFloat(x) < y) {
return true;
} else {
return false;
}
You need to use ParseFloat() not parceFloat() ...
parceFloat is not an existing function.
parceFloat() is not a function, the function is parseFloat()
A simple typo is all the error there is.

JQuery toFixed is not a function [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 have this JavaScript code:
if($('#numlic').val() <= 10) {
$('#totalprice').text(23.10 * $('#numlic').val()).toFixed(2);
}
but it doesn't work and I get the "toFixed is not a function" error.
Can you help me with this?
Thanks in advance.
It's a simple typo:
if($('#numlic').val() <= 10) {
$('#totalprice').text((23.10 * $('#numlic').val()).toFixed(2));
}
The toFixed function is an extension of a Number. You're trying to set the element $('#totalprice') .toFixed(2), when you want to set the result of "23.10 * $('#numlic').val()".

How to create statement if contains "!" [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
var input = message.content.toUpperCase();
if(input.indexOf("!")
{
bot.sendMessage(message, "!!!");
}
Help would be great, also earlier input was defined earlier
The String#indexOf method returns the index if found else returns -1. In your case .indexOf("!") return 0 and it's a false value and if statement never gets executed,so update your condition based on that.
if(input.indexOf("!") > -1)
or
if(input.indexOf("!") != -1)

How to pass value for the JavaScript statements? [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 want to pass a value to a Javascript Statement. Is it possible?
For Example :
function Show(msg, Id, Msgtype) { // I need to pass this Id argument to below javascript innerHtml statement
var strVar = "";
strVar = "Hello" + Msgtype + " <i class='icon-remove close'></i> " + msg + "</div>";
document.getElementById("???").innerHTML = strVar; // ??? should be the Id above in the function arguments
}
Or in other way, how can I achieve this scenario?
Just pass Id, like this
document.getElementById(Id).innerHTML = strVar;

Categories

Resources