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 tried using alert() and confirm() in JavaScript.
<!DOCTYPE html>
<html>
<head>
<title>
My Website
</title>
</head>
<body>
<br/>
<br/>
<br/>
<br/>
<h2 align=center>My Website</h2>
<p align=center> <button onclick=“myFunction()”>click to enter</button> </p>
<script type=text/javascript>
function myFunction() {
alert(“u sure?”);
}
</script>
</body>
</html>
Before you point it out, no, quotation marks glitch everything out on my website.
I tried something similar to this on another computer and it worked.
Is it just my computer?
The problem is likely with your double quotes. “ should be ":
function myFunction() {
alert("u sure?");
}
<p align=center> <button onclick="myFunction()">click to enter</button> </p>
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 7 months ago.
Improve this question
I am tearing my hair out over this. Why is foo() undefined when I click the button in this script?
<html>
<body>
<script type="text/javascript" src="./app2.js"/>
<script">
function foo() {
console.log('foo...');
}
</script>
<button type="button" onClick="foo()" id="testbutton">Click!</button>
<button type="button" onClick="hello()">Click hello!</button>
</body>
</html>
but not if I remove the first script tag?
<html>
<body>
<!-- <script type="text/javascript" src="./app2.js"/>-->
<script>
function foo() {
console.log('foo...');
}
</script>
<button type="button" onClick="foo()" id="testbutton">Click!</button>
</body>
</html>
My app2.js is just
function hello() {
console.log('hello');
}
I have tested in Chrome and Safari on macOS. The hello function works as expected.
Auto closing tags are used in React JSX and not in vanilla HTML
Replace
<script type="text/javascript" src="./app2.js"/>
with
<script type="text/javascript" src="./app2.js" ></script>
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 5 years ago.
Improve this question
Trying to assign array values in new array is giving error. Can someone help out why is it giving error?
<html>
<head>
<style>
</style>
</head>
<body>
<script>
var a=["red","yellow","pink","blue","aqua"];
var b=["rose","lotus","sunflower","lily","mogra"];
var c=["mango","banana","orange","blueberry","lichi"];
console.log(a[1]);
console.log(b[2]);
console.log(c[3]);
var d=[a[l],b[2],c[3]];
console.log(d);
</script>
</body>
</html>
You wrote an 'l' instead of a '1' on this line:
var d=[a[l],b[2],c[3]];
Fixed below:
<html>
<head>
<style>
</style>
</head>
<body>
<script>
var a=["red","yellow","pink","blue","aqua"];
var b=["rose","lotus","sunflower","lily","mogra"];
var c=["mango","banana","orange","blueberry","lichi"];
console.log(a[1]);
console.log(b[2]);
console.log(c[3]);
var d=[a[1],b[2],c[3]];
console.log(d);
</script>
</body>
</html>
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 little problem... in this code if I define only start() everything works, but when I declare time(), i got the error:
"TypeError: start is not a function". Where is the problem??
Here the code,
//start
function start(){
//removes title and start boxes
var body=document.getElementsByTagName("body")[0];
var start_box=document.getElementById("start_box");
var title_box=document.getElementById("title_box");
body.removeChild(start_box);
body.removeChild(title_box);
//creates stats box
var stats_box=document.createElement("div");
stats_box.id="stats_box";
var time=document.createElement("p");
time.id="time";
var points=document.createElement("p");
points.id="points";
stats_box.appendChild(points);
stats_box.appendChild(time);
body.appendChild(stats_box);
//creates play box
var play_box=document.createElement("div");
play_box.id="play_box";
body.appendChild(play_box);
}
//time
function time(){
var time=document.getElementById("time");
for(x=30,x>=0,x--){
time.innerHTML("Time:"+x);
}
}
<!DOCTYPE HTML>
<html>
<head>
<title>PICK 'EM ALL</title>
<link rel="stylesheet" href="pta.css" type="text/css">
<script src="pta.js" type="text/javascript"></script>
</head>
<body>
<div id="title_box">
<p id="title">PICK 'EM ALL</p>
</div>
<div id="start_box" onclick="start()">
<p id="start">START</p>
</div>
</body>
</html>
Issue is with for loop, it should be semi-colon instead of comma
for(x=30;x>=0;x--){
time.innerHTML("Time:"+x);
}
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
I'm searching for a simple, small templating engine which usage would be similar to this:
<html>
<head>
<script src="templating.js"></script>
<script>
var data = {
person: {
name: "John",
age: 28
}
};
templating(data);
</script>
<title>Site</title>
</head>
<body>
My name is {{person.name}} and I'm {{person.age}} years old.
</body>
</html>
What should result in a page rendering:
My name is John and I'm 28 years old.
I've looked over every single templating engine found here: http://engineering.linkedin.com/frontend/client-side-templating-throwdown-mustache-handlebars-dustjs-and-more and it I dind't find one which would work like that.
So the question is: am I missing something here, or is this kind of templating not a good practice for some reason?
Take a look at https://angularjs.org/
It uses a very similar syntax to what you provided
<!doctype html>
<html ng-app>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.0-beta.16/angular.min.js"></script>
</head>
<body>
<div>
<label>Name:</label>
<input type="text" ng-model="yourName" placeholder="Enter a name here">
<hr>
<h1>Hello {{yourName}}!</h1>
</div>
</body>
</html>
And has some extra features regarding templating you might find useful.
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
<!DOCTYPE html>
<html>
<head>
<title>Practice with condition statements.</title>
<script LANGUAGE="Javascript" type="text/javascript">
function myFunction()
{
if (document.getElementById(input1).value == John);
{
alert("This is correct!");
}
else
}
alert("This is incorrect!");
}
}
</script>
</head>
<body bgcolor="green">
Answer:<input type="text" name="answer" id="input1">
<button type="button" onclick="myFunction()">Submit</button>
</body>
</html>
I cannot for the life of me figure out why this function will not display alert messages. I've messed with it for at least an hour and a half and it is giving me a headache. I hope this isn't some easy fix that has been eluding my eyes. I am very new at this so please be gentle with any criticism. :C
input1 is not a variable or object, You must wrap it in "doublequotes" or 'singlequotes'. Use:
document.getElementById("input1").value
instead of:
document.getElementById(input1).value