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
I declare a global variable in JavaScript in header.php file but it is not accessible in footer.php file
Code:
header.php
<?php define('BASE_URL','https://example.com'); ?>
<!DOCTYPE html>
<html lang="en" xml:lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascipt">
var baseUrl = { url:"<?php echo BASE_URL; ?>" };
</script>
<meta charset="utf-8"/>
</head>
<body>
index.php
<?php
require_once("templates/header.php");
require_once("templates/footer.php");
footer.php
<script type="text/javascript">
alert(baseUrl.url);
</script>
</body>
</html>
At here I try to access baseUrl variable in footer.php file but I get this error
Uncaught ReferenceError: baseUrl is not defined
Looking for help!
You misspelled type="text/javascript". Fix that and it should work.
You have a typo, you wrote javascipt instead of javascript in the type="..." attribute.
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 last month.
Improve this question
I was trying to create a website where I could put in some data, and it would send GitHub API a POST request to create a file with the specified data. I am using GitHub Pages to host.
I created a test script that should create a file once the page loads, and it worked originally, but as I came back to test it again 2 hours later, it didn't create a file. What am I doing wrong? Note: I'm using personal tokens for this, is that an issue?
Here's my code:
index.html:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>Dev portal</title>
<link href="style.css" rel="stylesheet" type="text/css" />
</head>
<body>
Hello world
<script type="module" src="script.js"></script>
</body>
</html>
script.js:
import { Octokit } from "https://cdn.skypack.dev/#octokit/rest";
const octokit = new Octokit({
auth: 'iputmytokenhere'
})
await octokit.request('PUT /repos/{owner}/{repo}/contents/{path}', {
owner: 'Skoolgq',
repo: 'skoolgq.github.io',
path: 'test2.txt',
message: 'Test commits for JSON API',
committer: {
name: 'Skool Developers',
email: 'help#skool.gq'
},
content: 'bXkgbmV3IGZpbGUgY29udGVudHM='
})
Turns out I was using an existing filename. Silly me!
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 3 years ago.
Improve this question
I want to do something like
document.write("Your name is "+name+".");
but with innerHtml I tried
document.getElementById('example').innerHTML = "Your name is "+name+"."
and got an error
index.html:10 Uncaught ReferenceError: getElementById is not defined
at index.html:10
my code :
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<p id="example"></p>
<script type="text/javascript">
var name = "Mixlanded"
var example = getElementById('example')
example.innerHTML = 'Your name is ' + name + '.'
</script>
</body>
</html>
You code should work perfect
But, just check that your JavaScript code is executed after the Html code <div id="example"></div> is available
Code:
const name = 'Mixlanded'
document.getElementById('example').innerHTML = 'Your name is ' + name + '.'
<p id="example"></p>
just used document.getElementById('example') and error gone
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<p id="example"></p>
<script type="text/javascript">
var name = "Mixlanded"
var example = document.getElementById('example')
example.innerHTML = 'Your name is ' + name + '.'
</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 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 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
here below is my code i can't seem to find what is wrong it is not redirecting to the link.
<html>
<head>
<script type="text/javascript" src="<?= baseurl(); ?>/public/js/jquery-1.9.1.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$(function() { $("formRedirect").submit(); });
});
</script>
</head>
<body>
<form id='formRedirect' action="http://www.example.com/something/something.aspx" method="post"><input type="submit" name="redirect" value='<?= $token ?>'</form>
</body>
Try this:
<html>
<head>
<script type="text/javascript" src="<?= baseurl(); ?>/public/js/jquery-1.9.1.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$("#formRedirect").submit();
});
</script>
</head>
<body>
<form id='formRedirect' action="http://www.example.com/something/something.aspx" method="post"><input type="submit" name="redirect" value='<?= $token ?>'</form>
</body>
For id jquery detect them with #
Try like this
$("#formRedirect")[0].submit();
Use
$(document).ready(function() {});
or
$(function(){})
Both same
U have added $(function(){}); inside document.ready
$(function(){}); is similar to $(document).ready(function() {});
Use following code:
$(document).ready(function() {
$("#formRedirect").submit();
});
I find the Chrome console to be very helpful in debugging situations like this. I would start by making sure you are getting a result from your jQuery selector.
You can open the Chrome console by pressing F12
In the Chrome console, type $("formRedirect") and see if you get any results. You probably won't, since you are missing the # ID selector.
Next, try submitting your corrected jQuery object. If it doesn't work, try accessing the actual HTML object by adding in a [0] at the end of your selector, as suggested by #Anik.