JQuery Mobile testing a data- attribute for boolean value [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 a list of li tags in an unordered list and each li has an attribute called data-clicked=false. this if... else if... statement will test to see if data-clicked==true/false and then give an alert with the value of the attribute. The problem is that this is always alerting "true" when it should be "false" since by default at the start they are all set to false.
$("ul").click(function(event) {
if ($(event.target).data("clicked"==true)) {
alert("true")
}
else if ($(event.target).data("clicked"==false)) {
alert("false")
}
});
basically all I want to know is how I can test to see if the data-clicked attribute is true or false.

your condition
if ($(event.target).data("clicked"==true)) {
wont work. It should be
if ($(event.target).data("clicked")==true) {
and same would be the case for the else if part

Related

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.

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)

JQuery set input box value to this.value onclick? [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
$("#something1").click(function(){
$("#something2").val(this.val);
});
I'm trying to set the value of something2 to the value of something1 onclick ...
this.value not this.val
$("#something1").click(function(){
$("#something2").val(this.value);
});
this.val will be evaluated to undefined. And it will be passed into the .val() function. Eventually it will be ignored.
Technically, in the .val()'s function definition, the logic would be, if it was called without any parameter, then the value of the current element over which the .val() was called will be returned.
calling $("#something2").val(undefined) will be similar to $("#something2").val()
Or use the jQuery val function:
$("#x").click(function(){
$("#y").val($(this).val());
});

Jquery not behaving as expected [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
First I echoed a button using PHP with value='pause'.Then I wrote a simple if statement in jquery
$(":button").click(function(){
if($(this).attr("value") == "pause"){
alert($(this).attr("value"));
$(this).attr("value") = "play";
}else{
alert($(this).attr("value"));
$(this).attr("value") = "pause";
}
});
But the result is always alert("pause");
What I am trying to do is if I click the button with value='pause', i want to execute an ajax request and change its value to 'play' so that on the next click it will execute another bit of code and set its value back to pause.
This code is meaningless:
$(this).attr("value") = "pause";
That probably generated errors that you're not paying attention to. When working with JavaScript code, always have your console open.
What you want is:
$(this).attr("value", "pause");
Even better, as IFun points out:
$(this).val("pause");
Make sure to consult the attr() documentation.

Checking values when div is clicked [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
So, I have the script below and it successfully checks the values of the inputs when I click on a div with onclick="checkInputs()" inside.
But when I click the div again, it doesn't run the code. would I have to put return false; after it?
function checkInputs() {
if (document.getElementById("emailAdressInput").Value === "ADRESSHERE" && document.getElementById("passwordInput").Value === "PassHere")
{
document.getElementById("notifier").innerHTML = "Login Successful!";
}
else
{
document.getElementById("notifier").innerHTML = "Login Unsuccessful.";
}
}
To get the value of element you should use value not Value
document.getElementById("passwordInput").value
instead of
document.getElementById("passwordInput").Value;
UPDATE
Here is your working DEMO
The strict operator === checks for type also, If you put passHere instead of PassHere it reurns false.

Categories

Resources