Basic troubleshooting, Function onclick will not 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
<!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

Related

Why does my simple script tag break the following script tag? [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 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>

Assigning array values in new array giving error [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 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>

Javascript, TypeError: "function" is not a function [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 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);
}

JavaScript - Popups not working [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 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>

How do I make an Ajax post to a Twitter-like API [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 4 years ago.
Improve this question
I am very new to JavaScript and to AJAX. A friend has started helping me with a form that will post a status update to App.net, but I can't get it to work. I'm sure there are many errors in the code, but thanks in advance for any help.
<html>
<head>
<title>Post to App.net</title>
<link rel="stylesheet" type="text/css" href="style_post.css">
<script src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
<script>
function post()
</script>
<script type="text/javascript" language="javascript" src="count.js"></script>
<form id="post" method="post">
<textarea name="fixlength" value="What's on your mind?" id="posttext" maxlength="256" lengthcut="true"></textarea><br>
<input type="submit" value="Post" id="submit">
</form>
<label id="limitlbl_0" ><script> parseCharCounts(); </script></label>
<script type="text/javascript">
var frm = $('#post');
var token = window.location.href.substring(45,143),
var text = $('input[type="text"]').val()
frm.submit(function () {
$.ajax({
type: 'POST',
url: 'https://alpha-api.app.net/stream/0/posts',
data: {
text: 'test'
token: + token +'
},
success:
});
return false;
});
</script>
</body>
</html>
If you are making a larger app then you will definitely need to get the ajax calls working (you can make cross-domain posts as well as gets using CORS). However, for this particular situation, there is a simpler solution:
http://developers.app.net/docs/other/web-intents/
Using web intents you can use an iframe or redirect a user to a post form very easily. Just use the right URL and you are done. No JS required at all.
Here is the example above:
https://alpha.app.net/intent/post/?text=%40adn%20When%20is%20the%20next%20meetup%3F

Categories

Resources