How do I merge these two javascript codes? - javascript

I would like to add this code:
<script type="text/javascript" src="http://www.formstack.com/forms/js.php?1134414-uqmj2UXxEw-v2">
</script>
<noscript>
<a href="http://www.formstack.com/forms/CampusEnterprises-chopped_greens_order_form__copy" title="Online Form">
Online Form - Chopped Greens Order Form - COPY
</a>
</noscript>
into the call of the isOpen() method at the end of the following javascript code:
<head>
<script type="text/javascript">
var theDate = new Date();
var dayOfWeek = theDate.getUTCDay();
// Returns true if the restaurant is open
function isOpen()
{
//I'll fill this in later, for now, return true
return true;
}
</script>
</head><body>
<script type = "text/javascript">
if(isOpen())
{
//ADD CODE HERE
}
</script>
</body>
However, when I try to just copy and paste the two together it doesn't work. I think it has something to do with nested tags but I'm not sure

You can write out the script into the document dynamically.
<body>
<script type = "text/javascript">
if(isOpen())
{
document.write('<script type="text/javascript" src="http://www.formstack.com/forms/js.php?1134414-uqmj2UXxEw-v2"></script>');
}
</script>
<noscript>
<a href="http://www.formstack.com/forms/CampusEnterprises-chopped_greens_order_form__copy" title="Online Form">
Online Form - Chopped Greens Order Form - COPY
</a>
</noscript>
</body>
As #Jared Farrish noted in the comments, you might as well use the noscript tag directly on the page.

Related

how to find specific class in WP

I have a text that I would like to change ("Happy Clients" in the code below). I tried to find the text on the WP dashboard and in the template editor but with no luck, how can i locate the class so I'll be able to change the text?
<div class="_slider_shadow"></div>
</div><!-- /.carousel -->
<div class="count"><div class="count-info"><strong id="targetElem">0</strong><span class="count-description"> Happy Clients</span></div></div>
<script type="text/javascript">
EDIT
I found a file that contains the following code that is related to text that i want to change:
<div class="count"><div class="count-info"><strong id="targetElem">0</strong><span class="count-description"><?php the_field('text_for_count'); ?></span></div></div>
<script type="text/javascript">
var endVal = <?php the_field('count'); ?>;
var numAnim = new CountUp("targetElem", 0, endVal - 300, 0 , );
numAnim.start(function() {
numAnim.update(endVal);
});
</script>
You can install Query Monitor plugin. It has a section called Template which shows all template files that have been used to load the page. That should help you to find what you need.
Example output
Using jQuery you can do this :)
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("button").click(function(){
$(".count-description").text("No Clients");
});
});
</script>
</head>
<body>
<button>Click me</button>
<div class="enigma_slider_shadow"></div>
</div><!-- /.carousel -->
<div class="count"><div class="count-info"><strong id="targetElem">0</strong><span class="count-description"> Happy Clients</span></div></div>
</body>
</html>

Display stored images

I have some variables sessionStorage containing sources of images, and what i should do is displaying them. In my HTML page I tried like this:
</div>
<h1 id="h1poggia">
Here's your choices:
</h1>
<div>
<script src="Script1.js">
riep();
</script>
</div>
And this is the funcion:
function riep() {
imuno = sessionStorage.getItem('imuno');
imdue = sessionStorage.getItem('imdue');
document.write(imuno, imdue);
}
But it seems the function doesn't even get retrieved! Where am I wrong?
This doesn't works:
<script src="Script1.js">
riep();
</script>
If you need to include an external script and then call to function maybe you need to separate that:
<script src="Script1.js"></script>
<script>
riep();
</script>
However you are using document.write that's dangerous and deprecated. Please, use this instead:
document.getElementById("myDiv").innerHTML = imuno+", "+imdue;
And set an ID to the div:
<div id="myDiv"></div>

Change LaTeX when button is pressed

I am trying to create a program that generates random functions then shows them in LaTeX but I can't figure out how to edit LaTeX when a button is pressed.
This code works:
<html>
<head>
<script type="text/javascript" src="http://latex.codecogs.com/latexit.js"></script>
</head>
<body>
<div lang="latex" id='Latexdiv'></div>
<script>
document.getElementById('Latexdiv').innerHTML = 'sin(x)';
</script>
</body>
</html>
But this does not:
<html>
<head>
<script type="text/javascript" src="http://latex.codecogs.com/latexit.js"></script>
</head>
<body>
<div lang="latex" id='Latexdiv'></div>
<button onclick="change();">Change the LaTeX</button>
<script>
function change()
{
document.getElementById('Latexdiv').innerHTML = 'sin(x)';
}
</script>
</body>
</html>
I tried to use MathJax like this:
<html>
<body>
<button onclick='change();'>Change the LaTeX</button>
<div lang='latex' id='Latexdiv'></div>
<script type='text/javascript'>
var latexdiv = document.getElementById('Latexdiv');
function change()
{
var latex = document.createElement('script');
latex.src = 'http://latex.codecogs.com/latexit.js';
document.head.appendChild(latex);
var mathjax = document.createElement('script');
mathjax.src = 'https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML';
document.head.appendChild(mathjax);
latexdiv.innerHTML = '\\(sin(x)\\)';
};
</script>
</body>
</html>
This, unfortunately, only works the first time you press the button. If you press it twice, it just shows "\(sin(x)\)" in regular HTML. How would you get it to work twice?
http://latex.codecogs.com/latexit.js executes at the end:
LatexIT.add('*');
That adds and onload listener that executes a render function, that's why works in the first case, the page ends loading after your first script.
You could simply add the render function in your change function.
function change()
{
document.getElementById('Latexdiv').innerHTML = 'sin(x)';
LatexIT.render('*',false);
}

Redirect to another page on document.ready in android browsers

Im trying to redirect to another html page on load of one page. Below is my code (I want to automatically load 2.html when i open 1.html)
P.S: I could not use window.location.href because of specific use case
1.html
<html>
<head>
<script src="jquery-2.1.1.min.js"></script>
<script type = "text/javascript">
$( document ).ready(function() {
//$("#second")[0].click();
document.getElementById("second").click();
});
</script>
</head>
<body>
<a href = "2.html" id="second"/> click </a>
</body>
</html>
I tried $("#second")[0].click() and document.getElementById("second").click(). Both works fine in desktop browsers. But in android Both doesn't seems to work.
Do we have any ways to achieve it ? Please Help
Use this code.
Solution 1
<script>
function newPage() {
window.location.assign("http://www.adarshkr.com")
}
</script>
Solution 2
<script>
var url = "http://stackoverflow.com";
$(location).attr('href',url);
</script>
Thanks to #mod and #samsad. I resolved it in the following way,
<html>
<head>
<script src="jquery-2.1.1.min.js"></script>
<script type = "text/javascript">
window.onunload = function(){};
$( document ).ready(function() {
history.pushState({}, "", "1.html");
var url = "2.html";
window.location.assign(url);
});
</script>
</head>
<body>
<a href = "2.html" id="second"/> click </a>
</body>
</html>

Changing HTML embedded Code in Javascript function

What I'm Trying to do is to have a text field and a button, and create usernames, so when the user opens the first view he will be asked to enter his username. I created multiple chat rooms from a free service online and saved their embadable code.
The code for the embedable chat room:
<div id="tlkio" data-channel="lobby" style="width:100%;height:400px;"></div>
<script async src="http://tlk.io/embed.js" type="text/javascript"></script>
basically what I want to change from all of this is the date-channel I want it to change for example from "lobby" to "Mentors"
I Tried this:
<head>
<script type="text/javascript" >
var x;
function func() {
var r = document.getElementById("tlkio");
var a = document.getElementById("entr");
switch(a)
{
case "username1":
r.data-channel="lobby";
break;
case "username2":
r.data-channel="mentors";
break;
default:
void(0);
}
}
</script>
</head>
<body>
<form>
<input type="text" id="entr">
<input type="button" onclick="func()" value="go">
<div id="tlkio" data-channel="lobby" style="width:100%;height:400px;"></div>
<script async src="http://tlk.io/embed.js" type="text/javascript"></script>
</form>
</body>
And with no luck, I tried creating an empty div, and then embed all the embedable chat code in the javascript code, but it didn't work either. I searched for solutions but also with no luck :(
I really appreciate any help I could take with this problem.

Categories