+ 1
JavaScript
Guys, I want to write a code to accept a number(x) in a text box and display an image according to the sum i enter. Eg. If i enter 5 and i click the button(call the function) i want to see 5 images of Fanta bottles. Any Help? Thanks
4 Antworten
+ 3
<button onclick='
var no=prompt("Enter a no");
for(var i=0;i<no;i++)
{$("body").append("<img src='link.png'>"); } ' >
</button>
Using jquery
+ 1
u can keep ur image inside a loop
and the input value have to pass in loop
var x = document. getElementById (' ').val ()
for (y=0;y>=x;y++){}
+ 1
JavaScript without anything
<button id="myID">Click</button>
<script>
document.getElementById("myID").addEventListener("click",function() {
for(let i = parseInt(prompt("Number please"), 10)-1; i >= 0; i-=1){
let image = document.createElement("img");
image.src = "fanta.jpg";
document.body.appendChild(image);
}
});
</script>
+ 1
Thanks Guys. I appreciate the help..
I just need the JavaScript code to achieve my results this way
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>
<input type=“text” id=“nNum”>
<button onclick=“run_()”>Run</button>
</body>
</html>