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 4 years ago.
Improve this question
var discover = $filter("date")(new Date('08-24-2015'), "MM/dd/yyyy");
var occur = $filter("date")(new Date('06-07-2018'), "MM/dd/yyyy")
console.log(discover);
console.log(occur);
if (discover < occur) {
console.log('Discover less than occur');
} else {
console.log('No');
}
The result is always No to whatever value I assign to discover variable.
Did I compare it wrong?
I would advise you to use momentJS for date-time operations. It is much cleaner to implement.
To check if a certain time is before or after another time you could use their query functions
moment('2010-10-20').isBefore('2010-12-31', 'year'); // false
moment('2010-10-20').isBefore('2011-01-01', 'year'); // true
// Code goes here
var app = angular.module("app", []);
app.controller("BaseController", function($scope,$filter) {
var discover = $filter("date")(new Date('05-24-2015'), "MM/dd/yyyy");
var occur = $filter("date")(new Date('06-07-2018'), "MM/dd/yyyy")
console.log(discover);
console.log(occur);
if (discover < occur) {
console.log('Discover less than occur');
} else {
console.log('No');
}
});
<!DOCTYPE html>
<html>
<head>
<script data-require="angularjs#1.5.5" data-semver="1.5.5" src="https://code.angularjs.org/1.5.5/angular.js"></script>
<link rel="stylesheet" href="style.css" />
<script src="script.js"></script>
</head>
<body ng-app="app" ng-controller="BaseController">
</body>
</html>
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 years ago.
Improve this question
I'm trying to make to do list but keep getting TypeError: Cannot read property 'addEventListener' of null. I moved my script file to the bottom of the body tag and still get the error. I also tried putting it at the top and using defer and that didn't work. I tried using If(todoBTN) { todoBTN.addEventListener('click', addTodo) and it got rid of the error but when I ran a console.log test I didnt't see it get logged.
const todoBTN = document.querySelector('addtodo-btn')
const inputTodo = document.querySelector('todo-input')
const todoList = document.querySelector('todo-list')
const form = document.querySelector('form')
todoBTN.addEventListener('click', addTodo)
form.addEventListener('submit' , event => {
event.preventDefault();
})
function addTodo() {
// Create Div
const divTodo = document.createElement('div')
divTodo.classList.add('itemsDiv')
// Create To Do Item
const todoItem = document.createElement('li')
todoItem.innerText = inputTodo.value;
divTodo.appendChild(todoItem)
todoList.appendChild(divTodo)
}
<!DOCTYPE html>
<html lang="en">
<head>
<title>To do List</title>
<link rel="stylesheet" href="style.css">
<link href="https://fonts.googleapis.com/css2?family=Roboto+Slab&display=swap" rel="stylesheet">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.14.0/css/all.css"
integrity="sha384-HzLeBuhoNPvSl5KYnjx0BT+WB0QEEqLprO+NBkkk5gbc67FTaL7XIGa2w1L0Xbgc"
crossorigin="anonymous">
</head>
<body>
<h2>To Do List</h2>
<form class="form">
<input type="text" class="todo-input">
<button class="addtodo-btn" type="submit"><i class="fas fa-plus"></i></button>
</form>
<div class="todo-container">
<ul class="todo-list"></ul>
</div>
<script src="app.js"></script>
</body>
For class selector use . with in queryselector.See usage here
const todoBTN = document.querySelector('.addtodo-btn') // use . here for class
Same for others as well
const inputTodo = document.querySelector('.todo-input')
const todoList = document.querySelector('.todo-list')
const form = document.querySelector('.form')
You forget to add (.) in front of class name.
Closed. This question needs debugging details. It is not currently accepting answers.
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.
Closed 4 years ago.
Improve this question
<!Doctype html>
<html>
<title>JavaScript Tutorial</title>
<body>
<script language = "javascript">
var cleanCities = ["Cheyenne ","Santa Fe ","Tucson ","Great Falls ","Honolulu"];
var cityToCheck = "Tucson";
if(cityToCheck === cleanCities[i]) {
alert("You are clean");
}
</script>
</body>
</html>
I cannot find the errors
it's a javascript code
<!Doctype html>
<html>
<title>JavaScript Tutorial</title>
<body>
<script language = "javascript">
var cleanCities = ["Cheyenne ","Santa Fe ","Tucson ","Great Falls ","Honolulu"];
var cityToCheck = "Tucson";
if(cityToCheck === cleanCities[i]) {
alert("You are clean");
}
</script>
</body>
</html>
It says there is some problem in line 14
Where is your for loop for which you're an index i? If its removed intentionally then Tucson in your array has a space in the end. Use trim method.
Also language = "javascript" is wrong, its usually type="text/javascript"
The code should be like below:
enter code here
var cleanCities = ["Cheyenne ","Santa Fe ","Tucson ","Great Falls ","Honolulu"];
var cityToCheck = "Tucson";
for(var i=0; i<cleanCities.length; i++) {
if(cityToCheck === cleanCities[i].trim()){
alert('you are clean');
}
}
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
Code:
<html>
<body>
<script>
function mmm(x){
var val= [10,20,30];
return val;
}
</script>
<script>
function my(){
var va= mmm();
var b= va[1];
document.write(b);
}
</script>
</body>
</html>
there is a mistake in the above code, output is not generated. What I need is to display contents of 'val' of 'mmm(x)' function inside 'my()' function using document.write().
The two functions should be in different script tags. What are the changes do I need to make?
That's because you are not calling my function anywhere.
Try this.
<html>
<body>
<script>
function mmm(x){
var val= [10,20,30];
return val;
}
</script>
<script>
function my(){
var va= mmm(1);
var b= va[1];
document.write(b);
}
</script>
</body>
<button onclick="my()">click</button>
</html>
What I have done here I have a page having a button, and when you will click on that button, it will call that my function, and you will get 20 on your page.
You are not calling the function my
<html>
<body>
<script type="text/javascript">
function mmm(x){
var val= [10,20,30];
return val;
}
</script>
<script type="text/javascript">
function my(){
var va= mmm();
var b= va[1];
document.write(b);
}
my();
</script>
</body>
</html>
Try this code:
<script>
function mmm(){ //unwanted parameter is removed
var val= [10,20,30];
return val;
}
</script>
<script>
function my(){
var va= mmm();
var b= va[1];
document.write(b);
}
my();//calling method here
</script>
DEMO
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 get the following error: Uncaught SyntaxError: Unexpected end of input for line 1.
Here is the code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="./styles/default.css" />
<script src="./scripts/global.js"></script>
<script src="./scripts/jquery.js"></script>
<script>
$( document ).ready(function() {
var array = [ 'body_bg_2','body_bg_3','body_bg_4','body_bg_5' ];
var selected = array[Math.floor(Math.random() * array.length)];
$('<img src="./assets/'+selected+'.gif">').load(function() {
$(this).appendTo('body');
});
}
</script>
<title>Cats!</title>
</head>
I don't understand what the issue is? Anyone know of the solution?
You are missing closing ) of your document-ready handler
Use
<script>
$( document ).ready(function() {
var array = [ 'body_bg_2','body_bg_3','body_bg_4','body_bg_5' ];
var selected = array[Math.floor(Math.random() * array.length)];
$('<img src="./assets/'+selected+'.gif">').load(function() {
$(this).appendTo('body');
});
}); //<== Here you have missed )
</script>
$(document).ready(function () {
var array = [ 'body_bg_2', 'body_bg_3', 'body_bg_4', 'body_bg_5' ];
var selected = array[Math.floor(Math.random() * array.length)];
$('<img src="./assets/' + selected + '.gif">').load(function () {
$(this).appendTo('body');
});
}); /* <--- this is your fail */
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have a code in HTML using Spring notation.
The code is:
<c:if test="${testCSV==true}">
<img src="images/icons/edit.png" width="25" height="25" />
</c:if>
I want to check this condition in jQuery, So the condition checks dynamically.
please help me.
Add this code in html where you want to edit button to show
<a id="edit" href="#" onclick="editCSV(${command.id})" rel="tooltip-top">
<img src = "images/icons/edit.png" width = "25" height = "25" />
</a>
js
if (test == true) {
$('#edit').show();
} else {
$('#edit').hide();
}
pass true
<script type="text/javascript">
var test =pagetype('<%=${testCSV}%>');
if (test == true) {
$('#edit').show();
} else {
$('#edit').hide();
}
</script>
You can use this:
<script type="text/javascript">
var x = ${testCSV};
// some other code
</script>
The browser will see it as:
<script type="text/javascript">
var x = true; // or false
// some other code
</script>
Then, do whatever you like with it.