.src=Array[i] doesn't seem to work? [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'm trying to make a simple slide show and i'm trying to make the current src become the new array but it doesn't seem to work. I know i made an error somewhere but i can't find it. Help?
<!DOCTYPE html>
<html>
<head>
<script>
images = ["1.png", "2.png", "3.png", "4.png"];
for (i = 0; i < images.length; i++) {
document.getElementById("demo").src= images[i] ;
}
</script>
</head>
<body>
<img id="demo" src="1.png" style="width:500px;height:350px;border: 2px solid grey;">
</body>
</html>

I'm making a guess, but this is probably what you want: http://codepen.io/zvona/pen/rsIKi
Add script to DOMContentLoaded
use window.setTimeout()

Maybe the problem is in the for . You are using cars variable instead of images:
for (i = 0; i < images.length; i++)
Regards.

Related

get the current element in (inline function 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 1 year ago.
Improve this question
I am trying to get the element itself through making a function in the div itself I want when someone clicks on the current Element the Element should be deleted by fading in pure JavaScript I have searched on the internet but not getting the answer there are many similar questions on Stack Overflow but none of them giving me the combined answer(Like getting current element through Js in (inline function)).
So anyone can help me
<div style="width: 100px;height: 100px;background:red;" onclick="(function(ele){
console.log('helo')
console.log(ele.currentTarget)})();">
Thanks in advance
This should do it:
I added an id to your div which can be accessed through the getElementById.
<div id='hello' style="width: 100px;height: 100px;background:red;" onclick="
(
function() {
document.getElementById('hello').style.opacity = 0;
document.getElementById('hello').style.transition = '0.5s';
}
)();">

Missing a step? [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'm trying to do a basic math function and change the contents of a <p></p> element but when I click the button, it does nothing.
I know it's something trivial but I thought this would work.
What am I missing?
HTML
<button onclick="doMath()">Click</button>
<p id="output"></p>
JavaScript
function doMath() {
var total = 6/2(2+1);
document.getElementById("output").innerHTML = total;
}
function doMath() {
var total = (6/2*(2+1));
document.getElementById("output").innerHTML = total;
}
<button onclick="doMath()">Click</button>
<p id="output"></p>

Iframe content not displaying [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
I am trying to create an iframe in which the content changes based on a button click. However the iframe is not displaying any content. Could someone take a look at my code and explain why.
<script>
int i = 0;
var array= ["news1.html","news2.html","news3.html"];
function setURL(){
if (i<2) {
i = i+1;
}
else{
i=0;
};
document.getElementById("iframe").src = array[i];
}
</script>
<iframe id="iframe" style="float:right;" width="770" height="360"></iframe>
<button type="button" onclick="setURL()" style="float:right;"> Next </button>
I know it's not the best code in the world but as far as I can tell it should work so I was hoping for a hand with it please?
change your variable declaration from:
int i = 0;
to:
var i = 0;
Everything worked once i changed that.

My Controller is not working i dont know what is problum [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 don't know my controller is not working .
I m create a controller but is not working .
I know it's little mistake but i m see many times but now show .
Please Help me .
Angular Code
var myPanelSearch = angular.module('left-panel-search', []);
myPanelSearch.controller=('leftPanelSearch', function($scope){
$scope.msm = "Wincere";
});
HTML Code
<body ng-app="left-panel-search">
<div ng-controller="leftPanelSearch">
{{msm}} {{5+2}}
</div>
<h1>Hello Plunker!</h1>
</body>
Demo
Remove = sign after myPanelSearch.controller, it should be a method invocation, not assignment:
myPanelSearch.controller('leftPanelSearch', function($scope) {
$scope.msm = "Wincere";
});
Also you would have spotted the error if you kept developer console open.
Fixed demo.
Remove the = AFTER controller
.controller()
http://plnkr.co/edit/M8zz7qCu8ZEPn5YMPySX?p=preview

Change background image php loop [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 have a folder of images; I would like to create a page that lists each of them, and clicking them displays that image as the background.
I have got it working using
<img .... onclick='document.body.style.backgroundImage = url('img/1.jpg')' >
But when I put that into a FOREACH loop it doesn't work.
foreach($phpfiles as $phpfile)
{
echo "<img .... onclick='document.body.style.backgroundImage = url(".$phpfile.")' />";
}
Hope someone can help. Only thing I've found mentioned something about Javascript closures, but I couldn't follow the example it had
You have quotes mismatch. You are prematurely closing your ' single quotes.
Use a proper IDE to code.
Perhaps you forgot to include the path of each image file inside the loop.
foreach($phpfiles as $phpfile)
{
echo "<img .... onclick='document.body.style.backgroundImage = url('img/".$phpfile."')' />";
}

Categories