I'm using these functions to increment/decrement slider variable by 1.
function tstatUP()
{
var newValue = document.getElementById("range2").innerHTML;
newValue++;
if(newValue > 86) newValue = 86;
document.getElementById("tstatRange2").value = newValue;
document.getElementById("range2").innerHTML = newValue;
}
function tstatDN()
{
var newValue = document.getElementById("range2").innerHTML;
newValue--;
if(newValue < 72) newValue = 72;
document.getElementById("tstatRange2").value = newValue;
document.getElementById("range2").innerHTML = newValue;
}
but if I replace newValue++; with newValue+=0.5; I see undefined behavior when range2 updates:
as if it is being treated like a String.
I'm not experienced with HTML... here is the button HTML:
<div id="tstatSlider">
<h2>Thermostat Setting</h2>
<input id="tstatRange2" type="range" style="width: 200px; height 40px" min="72.0" max="86.0" value="76" step = "0.5" list="increments2" oninput="showMainTstatValue(this.value)" onchange="showMainTstatValue(this.value)">
<datalist id="increments2">
<option>72</option>
<option>74</option>
<option>76</option>
<option>78</option>
<option>80</option>
<option>82</option>
<option>84</option>
<option>86</option>
</datalist>
<span id="range2">76.0</span>°F
<br/> <br/>
<input type="button" class="button" onclick="sendMainTstatValue()" value = SUBMIT />
<br /><br />
</div>
<div id="tstatButtons">
<br />
<br />
<input type="button" class="button" value="UP" onclick="tstatUP()">
<br />
<input type="button" class="button" value="DOWN" onclick="tstatDN()">
</div>
This happens because innerHTML is returning you a String, the newValue++ operator is parsing internally to a number but the += is a valid operator on a string since you can make concatenations with it (therefore is being treated as a String):
var x = "foo"
x += "bar"; //This shoud be "foobar"
You just need to parse the value as a float number (using parseFloat) before manipulating it so it's treated as a number instead:
var newValue = parseFloat(document.getElementById("range2").innerHTML);
here is a fiddle with the solution: link
Here is the updated function
function tstatUP()
{
var newValue = parseFloat(document.getElementById("range2").innerHTML);
newValue+=0.5;
if(newValue > 86) newValue = 86;
document.getElementById("tstatRange2").value = newValue;
document.getElementById("range2").innerHTML = newValue;
}
function tstatDN()
{
var newValue = parseFloat(document.getElementById("range2").innerHTML);
newValue-=0.5;
if(newValue < 72) newValue = 72;
document.getElementById("tstatRange2").value = newValue;
document.getElementById("range2").innerHTML = newValue;
}
Related
I have in a spreadsheet, a MENU with buttons linked to other sheets.
Since I have many sheets, I want that when selecting a button it is the same for a group of those sheets.
Ex: btn "Enter approved teachers", there are 4 sheets that are to enter that data, each one corresponds to a different area.
That when I click on this button, I skip a "popup" that shows me a list of that sheets and lets me select it with an "OK".
The part of selecting the sheet with a script is easy to do with a youtube tutorial, but the control of sheets and selection I can not find anywhere.
I haven't been able to try anything, as I don't have experience coding in Apps Script or Js.
Hopefully this is close to what you are looking for:
This a dialog I use for selecting which files I wish to backup from my spreadsheets.
html:
<!DOCTYPE html>
<html>
<head>
<base target="_top">
<style>
input {margin: 2px 5px 2px 0;}
#btn3,#btn4{display:none}
</style>
</head>
<body>
<form>
<input type="text" id="scr" name="script" size="60" placeholder="Enter Apps Script Id" onchange="getFileNames();" />
<br /><input type="text" id="fldr" name="folder" size="60" placeholder="Enter Backup Folder Id" />
<div id="shts"></div>
<br /><input type="button" value="0" onClick="unCheckAll();" size="15" id="btn3" />
<input type="button" value="1" onClick="checkAll();"size="15" id="btn4"/>
<br /><input type="checkbox" id="files" name="saveFiles" checked /><label for="files">Save Files</label>
<br /><input type="checkbox" id="json" name="saveJson" checked /><label for="json">Save JSON</label>
<br /><input type="button" value="Submit" onClick="backupFiles();" />
</form>
<script>
function getFileNames() {
const scriptid = document.getElementById("scr").value;
google.script.run
.withSuccessHandler((names) => {
document.getElementById('btn3').style.display = "inline";
document.getElementById('btn4').style.display = "inline";
names.forEach((name,i) => {
let br = document.createElement("br");
let cb = document.createElement("input");
cb.type = "checkbox";
cb.id = `cb${i}`;
cb.name = `cb${i}`;
cb.className = "cbx";
cb.value = `${name}`;
cb.checked = true;
let lbl = document.createElement("label");
lbl.htmlFor = `cb${i}`;
lbl.appendChild(document.createTextNode(`${name}`));
document.getElementById("shts").appendChild(cb);
document.getElementById("shts").appendChild(lbl);
document.getElementById("shts").appendChild(br);
});
})
.getAllFileNames({scriptId:scriptid});
}
function unCheckAll() {
let btns = document.getElementsByClassName("cbx");
console.log(btns.length);
for(let i =0;i<btns.length;i++) {
btns[i].checked = false;
}
}
function checkAll() {
let btns = document.getElementsByClassName("cbx");
console.log(btns.length)
for(let i = 0;i<btns.length;i++) {
btns[i].checked = true;
}
}
function backupFiles() {
console.log('backupFiles');
sObj = {};
sObj.script = document.getElementById('scr').value;
sObj.folder = document.getElementById('fldr').value;
sObj.saveJson = document.getElementById('json').checked?'on':'';
sObj.saveFiles = document.getElementById('files').checked?'on':'';
sObj.selected = [];
console.log("1");
const cbs = document.getElementsByClassName("cbx");
let selected = [];
for(let i = 0;i<cbs.length; i++) {
let cb = cbs[i];
if(cb.checked) {
sObj.selected.push(cb.value)
}
}
console.log("2");
google.script.run
.withSuccessHandler(function(obj){google.script.host.close();})
.scriptFilesBackup(sObj);
console.log(JSON.stringify(sObj));
}
</script>
</body>
</html>
This is what the dialog looks like:
I'm trying to make a input sentence case tool but when I type anything different it keeps returning the value="" text.
I'd like to make an exception for pasted or replaced text. So when I type a new value in input it should return that string into sentence case.
Here is the code snippet I've made:
function capitalizeFirstLetter(string) {
return string.charAt(0).toUpperCase() + string.slice(1);
}
var title = $("#essay-title").val();
var sentenceCaseTitle = capitalizeFirstLetter(title.toLowerCase());
//alert( lowerCaseTitle );
function sentencecase() {
$("#essay-title").trigger("change paste");
$("#essay-title").val(sentenceCaseTitle);
}
https://jsfiddle.net/c105vedo/
var title = $("#essay-title").val(); is executed immediately on page visit, so it's always empty and not updated. Move that part inside sentencecase:
function capitalizeFirstLetter(string) {
return string.charAt(0).toUpperCase() + string.slice(1);
}
function sentencecase() {
var title = $("#essay-title").val();
var sentenceCaseTitle = capitalizeFirstLetter(title.toLowerCase());
$("#essay-title").trigger("change paste");
$("#essay-title").val(sentenceCaseTitle);
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input type="text" id="essay-title" value="TEST TITLE">
<button type="button" onclick="sentencecase()">OK
</button>
You have to move the following code into your sentencecase function,
var title = $("#essay-title").val();
var sentenceCaseTitle = capitalizeFirstLetter(title.toLowerCase());
Problem is that if the above code is outside of the function it will only be executed once, so that is why you keep getting the same value.
Demo
function capitalizeFirstLetter(string) {
return string.charAt(0).toUpperCase() + string.slice(1);
}
//alert( lowerCaseTitle );
function sentencecase() {
var title = $("#essay-title").val();
var sentenceCaseTitle = capitalizeFirstLetter(title.toLowerCase());
$("#essay-title").trigger("change paste");
$("#essay-title").val(sentenceCaseTitle);
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input type="text" id="essay-title" value="TEST TITLE">
<button type="button" onclick="sentencecase()">OK
</button>
So this snippet of code I am working on should be sufficient.
SHORT VERSION : I want to run a script, where using MAthJax, a script will output a (Number - number)^2 but in proper math as shown in the beginning of the code. I cannot quite understand why the MathJax won't render.
Line 237 Is the line that wont render :( but 238 does just fine (not mathjax but what I want to see :( )
<head>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>MathJax example</title>
<script type="text/javascript" async src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/latest.js?config=TeX-MML-AM_CHTML" async>
</script>
</head>
<body>
<div id="Table Section">
<!-- Needs to have one section for a value, dev and dev squared-->
<table id="Final Results">
<tr>
<!-- Needs to have one section for a value, dev and dev squared-->
<th>
<!-- Random Numbers -->
<p id="Random_Number_1"> R1C1</p>
</th>
<th>
<p id="Deviation_1">R1C2</p>
</th>
<th>
<p id="Deviation_Squared_1">R1C3</p>
</th>
</tr>
<tr>
<!-- Needs to have one section for a value, dev and dev squared-->
<th>
<!-- Random Numbers -->
<p id="Random_Number_2">R2C1</p>
</th>
<th>
<p id="Deviation_2">R2C2</p>
</th>
<th>
<p id="Deviation_Squared_2">R2C3</p>
</th>
</tr>
<tr>
<!-- Needs to have one section for a value, dev and dev squared-->
<th>
<!-- Random Numbers -->
<p id="Random_Number_3">R3C1</p>
</th>
<th>
<p id="Deviation_3">R3C2</p>
</th>
<th>
<p id="Deviation_Squared_3">R3C3</p>
</th>
</tr>
<tr>
<!-- Needs to have one section for a value, dev and dev squared-->
<th>
<!-- Random Numbers -->
<p id="Random_Number_4">R4C1</p>
</th>
<th>
<p id="Deviation_4">R4C2</p>
</th>
<th>
<p id="Deviation_Squared_4">R4C3</p>
</th>
</tr>
</table>
<p id="Sum_of_All_Numbers_For_User"></p>
<p id="Sample_Size_Is"></p>
<p id="Average_is"></p>
<p id="Sum_of_Squared_Deviations_is"></p>
<p id="Variance_is"></p>
<p id="Standard_Deviation_Final_Answer"></p>
</div>
<div id="Beginning_Instructions">
<p id="Instruction_Number_One">Click the button to display a random number between 1 and 100.</p>
<p id="Instruction_Number_Two">Once you begin, you will be prompted to find the average of those 4 numbers that will pop up</p>
<button onclick="Random_Number_Generator_and_Solver()">Try it</button>
<p id="Testing Ground"> $$ (a-b)^2 $$</p>
</div>
<div id="Average">
<div id="Average_Instructions" hidden>
<p id="Average_Instructions_Number_Technical"> First let us try to find the sum of all of the random numbers.</p>
<p id="Average_Instructions_Number_Simplified"> In short add them all up </p>
<p id="Average_Sum_Value_Text">So the sum of all of those numbers is... <input id="User_Sum_of_Numbers"><button onclick="Sum_of_All_Numbers()">Is this my sum?</button></p>
<p id="The_Sum_Is" hidden> Incorrect Please add them up again</p>
</div>
<div id="Average_Instructions_Part_2" hidden>
<p id="Average_Instructions_Sample_Size"> How many numbers from the data set are we dealing with?<input id="User_Sample_Size">Is this my Sample Size?<button onclick="Sample_Size_for_Average()"> Check my Sample Size </button> </p>
<p id="Incorrect_Sample_Size" hidden> Hint: How many numbers are in the first column?</p>
</div>
<div id="Average_Instructions_Part_3" hidden>
<p id="Average_Instructions_Division"> So the actual average is the sum / sample size and that is <input id="User_Average"><button onclick="Continue_to_Deviations()"> Check my Average </button> </p>
<p id="incorrect average" hidden>Sorry check that again</p>
</div>
</div>
<div id="Deviation">
<div id="Find_Deviation_1" hidden>
<p id="Insert_Deviation_Equation_1"></p> <input id="User_Deviation_1"></input>
<button onclick="First_Deviation()">Check It</button>
<p id="Error_First_Deviation" hidden> Sorry that is not correct try again
</div>
<div id="Find_Deviation_2" hidden>
<p id="Insert_Deviation_Equation_2"></p> <input id="User_Deviation_2"></input> <button onclick="Second_Deviation()">Check It</button>
<p id="Error_Second_Deviation" hidden> Sorry that is not correct try again
</div>
<div id="Find_Deviation_3" hidden>
<p id="Insert_Deviation_Equation_3"></p><input id="User_Deviation_3"></input>
<button onclick="Third_Deviation()">Check It</button>
<p id="Error_Third_Deviation" hidden> Sorry that is not correct try again
</div>
<div id="Find_Deviation_4" hidden>
<p id="Insert_Deviation_Equation_4"></p><input id="User_Deviation_4"></input>
<button onclick="Fourth_Deviation()">Check It</button>
<p id="Error_Fourth_Deviation" hidden> Sorry that is not correct try again
</div>
</div>
<div id="Deviations Squared">
<div id="Find_Deviation_Squared_1">
<p id="Insert_Deviation_Squared_Equation_1"></p> <input id="User_Deviation_Squared_1"></input>
<button onclick="First_Deviation_Squared()">Check It</button>
<p id="Error_First_Deviation_Squared" hidden> Sorry that is not correct try again
</div>
<div id="Find_Deviation_Squared_2" hidden>
<p id="Insert_Deviation_Squared_Equation_2"></p> <input id="User_Deviation_Squared_2"></input> <button onclick="Second_Deviation_Squared()">Check It</button>
<p id="Error_Second_Deviation_Squared" hidden> Sorry that is not correct try again
</div>
<div id="Find_Deviation_Squared_3" hidden>
<p id="Insert_Deviation_Squared_Equation_3"></p><input id="User_Deviation_Squared_3"></input>
<button onclick="Third_Deviation_Squared()">Check It</button>
<p id="Error_Third_Deviation_Squared" hidden> Sorry that is not correct try again
</div>
<div id="Find_Deviation_Squared_4" hidden>
<p id="Insert_Deviation_Squared_Equation_4"></p><input id="User_Deviation_Squared_4"></input>
<button onclick="Fourth_Deviation_Squared()">Check It</button>
<p id="Error_Fourth_Deviation_Squared" hidden> Sorry that is not correct try again
</div>
</div>
<div id="Final Stage">
<div id="Add Squared Deviations" hidden>
<p> Now you need to find the sum of every number in the third column <input id="User_Sum_Squared_Deviations"><button onclick="Squared_Deviations_Sum()">Check it</button>
</div>
<div id="Divide By Sample Size" hidden>
<p> Take the Sum of Squared Deviations and Divide that by the sample size <input id="Variance"><button onclick="Variance_Calculation()">Check it</p>
</div>
<div id="Take The Square Root" hidden>
<p> This is the final stage, take the square root of your value. Round to 3 decimal places <input id="Standard_Deviation_User"><button onclick="Final_Stage()">Check it </button>
</div>
</div>
<div id="Finished" hidden>
<p> You have completed the course :)</p>
</div>
<div id="Background_Math" hidden>
<p id="First_Random_Value"> <input id="First_Random_Value_Fixed"></p>
<p id="First_Random_Deviation"><input id="First_Random_Deviation_Fixed"></p>
<p id="First_Random_Deviation_Squared"><input id="First_Random_Deviation_Squared_Fixed"></p>
<p id="Second_Random_Value"> <input id="Second_Random_Value_Fixed"></p>
<p id="Second_Random_Deviation"> <input id="Second_Random_Deviation_Fixed"></p>
<p id="Second_Random_Deviation_Squared"><input id="Second_Random_Deviation_Squared_Fixed"></p>
<p id="Third_Random_Value"> <input id="Third_Random_Value_Fixed"></p>
<p id="Third_Random_Deviation"><input id="Third_Random_Deviation_Fixed"></p>
<p id="Third_Random_Deviation_Squared"><input id="Third_Random_Deviation_Squared_Fixed"></p>
<p id="Fourth_Random_Value"> <input id="Fourth_Random_Value_Fixed"></p>
<p id="Fourth_Random_Deviation"><input id="Fourth_Random_Deviation_Fixed"></p>
<p id="Fourth_Random_Deviation_Squared"><input id="Fourth_Random_Deviation_Squared_Fixed"></p>
<p id="Sum_of_All_Numbers_Value"> <input id="Sum_of_All_Numbers_Fixed"></p>
<p id="Average_Value"> <input id="Average_Value_Fixed"></p>
<p id="Sum_of_Squared_Deviations_Value"> <input id="Sum_of_Squared_Deviations_Fixed"></p>
<p id="Variance_Value"> <input id="Variance_Value_Fixed"></p>
<p id="Standard_Deviation_Value"> <input id="Standard_Deviation_Fixed"></p>
</div>
<script>
function Random_Number_Generator_and_Solver() {
var Random_Number_R1_C1 = Math.floor((Math.random() * 100) + 1);
document.getElementById("Random_Number_1").innerHTML = Random_Number_R1_C1;
document.getElementById("First_Random_Value_Fixed").value = Random_Number_R1_C1;
var Random_Number_R2_C1 = Math.floor((Math.random() * 100) + 1);
document.getElementById("Random_Number_2").innerHTML = Random_Number_R2_C1;
document.getElementById("Second_Random_Value_Fixed").value = Random_Number_R2_C1;
var Random_Number_R3_C1 = Math.floor((Math.random() * 100) + 1);
document.getElementById("Random_Number_3").innerHTML = Random_Number_R3_C1;
document.getElementById("Third_Random_Value_Fixed").value = Random_Number_R3_C1;
var Random_Number_R4_C1 = Math.floor((Math.random() * 100) + 1);
document.getElementById("Random_Number_4").innerHTML = Random_Number_R4_C1;
document.getElementById("Fourth_Random_Value_Fixed").value = Random_Number_R4_C1;
var Sum_of_Values = Random_Number_R1_C1 + Random_Number_R2_C1 + Random_Number_R3_C1 + Random_Number_R4_C1;
document.getElementById("Sum_of_All_Numbers_Fixed").value = Sum_of_Values;
var Average = Sum_of_Values / 4;
document.getElementById("Average_Value_Fixed").value = Average;
var Sum_of_Squared_Deviations = Math.pow((Random_Number_R1_C1 - Average), 2) + Math.pow((Random_Number_R2_C1 - Average), 2) + Math.pow((Random_Number_R3_C1 - Average), 2) + Math.pow((Random_Number_R4_C1 - Average), 2);
document.getElementById("Sum_of_Squared_Deviations_Fixed").value = Sum_of_Squared_Deviations;
var Variance = Sum_of_Squared_Deviations / 4;
document.getElementById("Variance_Value_Fixed").value = Variance;
var Standard_Deviation = Math.pow(Variance, .5);
document.getElementById("Standard_Deviation_Fixed").value = Standard_Deviation;
var Deviation_1 = Random_Number_R1_C1 - Average;
document.getElementById("First_Random_Deviation_Fixed").value = Deviation_1;
var Deviation_2 = Random_Number_R2_C1 - Average;
document.getElementById("Second_Random_Deviation_Fixed").value = Deviation_2;
var Deviation_3 = Random_Number_R3_C1 - Average;
document.getElementById("Third_Random_Deviation_Fixed").value = Deviation_3;
var Deviation_4 = Random_Number_R4_C1 - Average;
document.getElementById("Fourth_Random_Deviation_Fixed").value = Deviation_4;
var Deviation_1_Squared = Math.pow(Deviation_1, 2);
document.getElementById("First_Random_Deviation_Squared_Fixed").value = Deviation_1_Squared;
var Deviation_2_Squared = Math.pow(Deviation_2, 2);
document.getElementById("Second_Random_Deviation_Squared_Fixed").value = Deviation_2_Squared;
var Deviation_3_Squared = Math.pow(Deviation_3, 2);
document.getElementById("Third_Random_Deviation_Squared_Fixed").value = Deviation_3_Squared;
var Deviation_4_Squared = Math.pow(Deviation_4, 2);
document.getElementById("Fourth_Random_Deviation_Squared_Fixed").value = Deviation_4_Squared;
document.getElementById("Insert_Deviation_Equation_1").innerHTML = "Now let us calcululate your first deviation " + Random_Number_R1_C1 + " - " + Average;
document.getElementById("Insert_Deviation_Equation_2").innerHTML = "Now let us calcululate your second deviation " + Random_Number_R2_C1 + " - " + Average;
document.getElementById("Insert_Deviation_Equation_3").innerHTML = "Now let us calcululate your third deviation " + Random_Number_R3_C1 + " - " + Average;
document.getElementById("Insert_Deviation_Equation_4").innerHTML = "Now let us calcululate your fourth deviation " + Random_Number_R4_C1 + " - " + Average;
var squared = "<sup>2</sup>"
document.getElementById("Insert_Deviation_Squared_Equation_1").innerHTML = "Now let us calcululate your first Deviation Squared $$ (" + Random_Number_R1_C1 + " - " + Average + ")^2 $$"
document.getElementById("Insert_Deviation_Squared_Equation_2").innerHTML = "Now let us calcululate your second Deviation Squared (" + Random_Number_R2_C1 + " - " + Average + ")" + squared
document.getElementById("Insert_Deviation_Squared_Equation_3").innerHTML = "Now let us calcululate your third Deviation Squared (" + Random_Number_R3_C1 + " - " + Average + ")" + squared
document.getElementById("Insert_Deviation_Squared_Equation_4").innerHTML = "Now let us calcululate your fourth Deviation Squared (" + Random_Number_R4_C1 + " - " + Average + ")" + squared
var x = document.getElementById("Beginning_Instructions");
x.style.display = 'none';
var x = document.getElementById("Average_Instructions");
x.style.display = 'block';
}
function Sum_of_All_Numbers() {
var User_Sum = document.getElementById("User_Sum_of_Numbers").value
var Calc_Sum = document.getElementById("Sum_of_All_Numbers_Fixed").value
if (User_Sum == Calc_Sum) {
var Show_Average_Part_2 = document.getElementById("Average_Instructions_Part_2")
Show_Average_Part_2.style.display = 'block'
var Hide_Average_Instructions = document.getElementById("Average_Instructions")
Hide_Average_Instructions.style.display = 'none'
var Fixed_Sum_Value = document.getElementById("Sum_of_All_Numbers_Fixed").value
document.getElementById("Sum_of_All_Numbers_For_User").innerHTML = "The sum of all the numbers is " + Fixed_Sum_Value
} else {
var Incorrect = document.getElementById("The_Sum_Is")
Incorrect.style.display = 'block'
}
}
function Sample_Size_for_Average() {
var sample_size = document.getElementById("User_Sample_Size").value
if (sample_size == 4) {
var Show_Average_Part_3 = document.getElementById("Average_Instructions_Part_3")
Show_Average_Part_3.style.display = 'block'
var Hide_Average_Part_2 = document.getElementById("Average_Instructions_Part_2")
Hide_Average_Part_2.style.display = 'none'
document.getElementById("Sample_Size_Is").innerHTML = "The Sample Size is " + sample_size
} else {
var Show_Incorrect_Sample_Size = document.getElementById("Incorrect_Sample_Size")
Show_Incorrect_Sample_Size.style.display = 'block'
}
}
function Continue_to_Deviations() {
var User_Average = document.getElementById("User_Average").value
var Actual_Average = document.getElementById("Average_Value_Fixed").value
if (User_Average == Actual_Average) {
var Hide_Average_3 = document.getElementById("Average_Instructions_Part_3")
Hide_Average_3.style.display = 'none'
var Next_Section = document.getElementById("Find_Deviation_1")
Next_Section.style.display = 'block'
document.getElementById("Average_is").innerHTML = "The Average is " + Actual_Average
} else {
var Incorrect = document.getElementById("incorrect average")
Incorrect.style.display = 'block'
}
}
function First_Deviation() {
var Exact = document.getElementById("First_Random_Deviation_Fixed").value
var Student = document.getElementById("User_Deviation_1").value
if (Exact == Student) {
var Show_Deviation_2 = document.getElementById("Find_Deviation_2")
Show_Deviation_2.style.display = 'block'
var hide_deviation_1 = document.getElementById("Find_Deviation_1")
hide_deviation_1.style.display = 'none'
document.getElementById("Deviation_1").innerHTML = Exact
} else {
var Error_First_Deviation = document.getElementById("Error_First_Deviation")
Error_First_Deviation.style.display = 'none'
}
}
function Second_Deviation() {
var Exact = document.getElementById("Second_Random_Deviation_Fixed").value
var Student = document.getElementById("User_Deviation_2").value
if (Exact == Student) {
var Show_Deviation_2 = document.getElementById("Find_Deviation_3")
Show_Deviation_2.style.display = 'block'
var hide_deviation_1 = document.getElementById("Find_Deviation_2")
hide_deviation_1.style.display = 'none'
document.getElementById("Deviation_2").innerHTML = Exact
} else {
var Error_First_Deviation = document.getElementById("Error_Second_Deviation")
Error_First_Deviation.style.display = 'none'
}
}
function Third_Deviation() {
var Exact = document.getElementById("Third_Random_Deviation_Fixed").value
var Student = document.getElementById("User_Deviation_3").value
if (Exact == Student) {
var Show_Deviation_2 = document.getElementById("Find_Deviation_4")
Show_Deviation_2.style.display = 'block'
var hide_deviation_1 = document.getElementById("Find_Deviation_3")
hide_deviation_1.style.display = 'none'
document.getElementById("Deviation_3").innerHTML = Exact
} else {
var Error_First_Deviation = document.getElementById("Error_Third_Deviation")
Error_First_Deviation.style.display = 'none'
}
}
function Fourth_Deviation() {
var Exact = document.getElementById("Fourth_Random_Deviation_Fixed").value
var Student = document.getElementById("User_Deviation_4").value
if (Exact == Student) {
var Show_Deviation_2 = document.getElementById("Find_Deviation_Squared_1")
Show_Deviation_2.style.display = 'block'
var hide_deviation_1 = document.getElementById("Find_Deviation_4")
hide_deviation_1.style.display = 'none'
document.getElementById("Deviation_4").innerHTML = Exact
} else {
var Error_First_Deviation = document.getElementById("Error_Fourth_Deviation")
Error_First_Deviation.style.display = 'none'
}
}
function First_Deviation_Squared() {
var Exact = document.getElementById("First_Random_Deviation_Squared_Fixed").value
var Student = document.getElementById("User_Deviation_Squared_1").value
if (Exact == Student) {
var Show_Deviation_2 = document.getElementById("Find_Deviation_Squared_2")
Show_Deviation_2.style.display = 'block'
var hide_deviation_1 = document.getElementById("Find_Deviation_Squared_1")
hide_deviation_1.style.display = 'none'
document.getElementById("Deviation_Squared_1").innerHTML = Exact
} else {
var Error_First_Deviation = document.getElementById("Error_First_Deviation_Squared")
Error_First_Deviation.style.display = 'none'
}
}
function Second_Deviation_Squared() {
var Exact = document.getElementById("Second_Random_Deviation_Squared_Fixed").value
var Student = document.getElementById("User_Deviation_Squared_2").value
if (Exact == Student) {
var Show_Deviation_2 = document.getElementById("Find_Deviation_Squared_3")
Show_Deviation_2.style.display = 'block'
var hide_deviation_1 = document.getElementById("Find_Deviation_Squared_2")
hide_deviation_1.style.display = 'none'
document.getElementById("Deviation_Squared_2").innerHTML = Exact
} else {
var Error_First_Deviation = document.getElementById("Error_Second_Deviation_Squared")
Error_First_Deviation.style.display = 'none'
}
}
function Third_Deviation_Squared() {
var Exact = document.getElementById("Third_Random_Deviation_Squared_Fixed").value
var Student = document.getElementById("User_Deviation_Squared_3").value
if (Exact == Student) {
var Show_Deviation_2 = document.getElementById("Find_Deviation_Squared_4")
Show_Deviation_2.style.display = 'block'
var hide_deviation_1 = document.getElementById("Find_Deviation_Squared_3")
hide_deviation_1.style.display = 'none'
document.getElementById("Deviation_Squared_3").innerHTML = Exact
} else {
var Error_First_Deviation = document.getElementById("Error_Third_Deviation_Squared")
Error_First_Deviation.style.display = 'none'
}
}
function Fourth_Deviation_Squared() {
var Exact = document.getElementById("Fourth_Random_Deviation_Squared_Fixed").value
var Student = document.getElementById("User_Deviation_Squared_4").value
if (Exact == Student) {
var Show_Deviation_2 = document.getElementById("Add Squared Deviations")
Show_Deviation_2.style.display = 'block'
var hide_deviation_1 = document.getElementById("Find_Deviation_Squared_4")
hide_deviation_1.style.display = 'none'
document.getElementById("Deviation_Squared_4").innerHTML = Exact
} else {
var Error_First_Deviation = document.getElementById("Error_Fourth_Deviation_Squared")
Error_First_Deviation.style.display = 'none'
}
}
function Squared_Deviations_Sum() {
var Exact = document.getElementById("Sum_of_Squared_Deviations_Fixed").value
var Student = document.getElementById("User_Sum_Squared_Deviations").value
if (Exact = Student) {
var hide_deviation_squared_1 = document.getElementById("Add Squared Deviations")
hide_deviation_squared_1.style.display = 'none'
var hide_divide_by_sample_size = document.getElementById("Divide By Sample Size")
hide_divide_by_sample_size.style.display = 'block'
document.getElementById("Sum_of_Squared_Deviations_is").innerHTML = "Sum of squared devations is " + Student
}
}
function Variance_Calculation() {
var Exact = document.getElementById("Variance_Value_Fixed").value
var Student = document.getElementById("Variance").value
if (Exact == Student) {
var hide = document.getElementById("Divide By Sample Size")
hide.style.display = 'none'
var show = document.getElementById("Take The Square Root")
show.style.display = 'block'
document.getElementById("Variance_is").innerHTML = "The Variance is " + Student
}
}
</script>
</body>
</html>
I unhid the section I care most about. As you can see when you load the code, the id=Testing Area renders the code fine. I tried to duplicate it in the script down below... Figure I would show the whole code that does work in a brower. Note : had to delete a couple of functions at the end of it due to size restriction.
There is a weird spacing between the elements of the original div that is coded in the html but i am unable to remove it no matter what.
<body>
<form class='myform'>
<div class='form-block'>
<span class='line'>1</span>
<button class='new-line'>New Line</button>
<button class='new-nested'>New Nested Line</button>
<input class='input' type='text' placeholder='Enter Value...'>
<button class='new-input'>Add input</button>
</div>
</form>
</body>
Please find the fiddle here:
function createNode() {
var div = document.createElement('div');
div.setAttribute('class', 'form-block');
var span = document.createElement('span');
span.setAttribute('class', 'line');
var b1 = document.createElement('button');
b1.setAttribute('class', 'new-line');
b1.textContent = 'New Line';
var b2 = document.createElement('button');
b2.setAttribute('class', 'new-nested');
b2.textContent = 'New Nested Line';
var b3 = document.createElement('button');
b3.setAttribute('class', 'new-input');
b3.textContent = 'Add input';
var ip = document.createElement('input');
ip.setAttribute('class', 'input');
ip.setAttribute('type', 'text');
ip.setAttribute('placeholder', 'Enter Value...');
div.insertAdjacentHTML("beforeend", span.outerHTML);
div.insertAdjacentHTML("beforeend", b1.outerHTML);
div.insertAdjacentHTML("beforeend", b2.outerHTML);
div.insertAdjacentHTML("beforeend", ip.outerHTML);
div.insertAdjacentHTML("beforeend", b3.outerHTML);
var d2 = document.getElementsByClassName("form-block")[0];
return div;
};
function newLine() {
console.log("new line");
var toBeAdded = createNode();
var theDivParent = this.parentElement.parentElement;
var previousLast;
var had = theDivParent.lastChild.hasChildNodes();
if (had) {
previousLast = theDivParent.lastChild.getElementsByClassName("line")[0].innerText.split(".");
var len = previousLast.length;
var num = parseInt(previousLast[len - 1]);
num++;
previousLast[len - 1] = num;
}
theDivParent.insertAdjacentHTML("beforeend", toBeAdded.outerHTML);
var len = theDivParent.getElementsByClassName("form-block").length;
if (!had) {
theDivParent.lastChild.getElementsByClassName("line")[0].innerText = 2;
} else {
theDivParent.lastChild.getElementsByClassName("line")[0].innerText = previousLast.join(".");
}
theDivParent.lastChild.getElementsByClassName("new-line")[0].onclick = newLine;
theDivParent.lastChild.getElementsByClassName("new-input")[0].onclick = newInput;
theDivParent.lastChild.getElementsByClassName("new-nested")[0].onclick = newNested;
return false;
};
function newNested() {
console.log("new line");
var toBeAdded = createNode();
var theDiv = this.parentElement;
theDiv.insertAdjacentHTML("beforeend", toBeAdded.outerHTML);
var len = theDiv.getElementsByClassName("form-block").length;
theDiv.lastChild.getElementsByClassName("line")[0].innerText = theDiv.getElementsByClassName("line")[0].innerText + "." + len;
theDiv.lastChild.getElementsByClassName("new-line")[0].onclick = newLine;
theDiv.lastChild.getElementsByClassName("new-input")[0].onclick = newInput;
theDiv.lastChild.getElementsByClassName("new-nested")[0].onclick = newNested;
return false;
};
function newInput() {
console.log("new input");
var elem = document.getElementsByClassName("input");
this.insertAdjacentHTML("beforebegin", elem[0].outerHTML);
return false;
};
document.getElementsByClassName("new-input")[0].onclick = newInput;
document.getElementsByClassName("new-line")[0].onclick = newLine;
document.getElementsByClassName("new-nested")[0].onclick = newNested;
document.getElementsByClassName("myform")[0].onsubmit = function () {
return false;
}
div {
padding: 0;
margin: 0;
background: green;
}
button {}
input {}
span {
background: red;
}
<body>
<form class='myform'>
<div class='form-block'>
<span class='line'>1</span>
<button class='new-line'>New Line</button>
<button class='new-nested'>New Nested Line</button>
<input class='input' type='text' placeholder='Enter Value...'>
<button class='new-input'>Add input</button>
</div>
</form>
</body>
Read this arcticle: https://css-tricks.com/fighting-the-space-between-inline-block-elements/
The HTML makes spaces between inline-block elements. When you press CTRL + A you can see there's a single space.
To fight this space you can do the following (mentioned in the arcticle aswell):
Open the tag on the previous line:
<ul>
<li>
one</li><li>
two</li><li>
three</li>
</ul>
Add the last closing brackets on the new line:
<ul>
<li>one</li
><li>two</li
><li>three</li>
</ul>
Or put comments, starting from the previous line to the following line.
<ul>
<li>one</li><!--
--><li>two</li><!--
--><li>three</li>
</ul>
I hope this helps :)
You can use float css property to remove the whitespace between elements.
<body>
<form class='myform'>
<div class='form-block'>
<span class='line floated'>1</span>
<button class='new-line floated'>New Line</button>
<button class='new-nested floated'>New Nested Line</button>
<input class='input floated' type='text' placeholder='Enter Value...'>
<button class='new-input floated'>Add input</button>
</div>
.floated {
float:left;
}
Updated JS Fiddle here: https://jsfiddle.net/ranjitsachin/LL7n983c/1/
add this style to the css file:
button { float: left; }
JSFiddle
here is update fiddle
I have removed the space between tags like
<span class='line'>1</span><button class='new-line'>New Line</button><button class='new-nested'>New Nested Line</button><input class='input' type='text' placeholder='Enter Value...'><button class='new-input'>Add input</button>
How can I have an alert box pop up if the number in the Answer_2 field is greater than 10, or less than -10?
Here's my example
Javascript:
function CalculateIMSUB(Atext, Btext, form, val)
{
var A = eval(Atext);
var B = eval(Btext);
if (isNaN(A)) A = 0;
if (isNaN(B)) B = 0;
var answer = A - B;
form.Answer.value = answer;
var diff = answer - val;
if (diff == 0)
form.Answer_2.value = 'ok';
else if (diff < 0)
form.Answer_2.value = diff;
else
form.Answer_2.value = '+' + diff;
}
function calculateAll() {
var forms = document.getElementsByTagName("form");
for(var i = 0; i < forms.length; i++ ) {
CalculateIMSUB(forms[i].input_A.value, forms[i].input_B.value,forms[i], 96)
}
}
HTML:
<FORM NAME="Calculator" METHOD="GET">
<P><INPUT TYPE=TEXT NAME="input_A" SIZE=10><INPUT TYPE=TEXT NAME="input_B" SIZE=10>
<INPUT TYPE="button" VALUE="+" name="subtractbutton" onclick="CalculateIMSUB
(this.form.input_A.value, this.form.input_B.value, this.form, 96)">
<INPUT TYPE=TEXT NAME="Answer" SIZE=12><tt>96</tt><INPUT TYPE=TEXT NAME="Answer_2"
SIZE=4></P></form>
<input type="button" onclick="calculateAll()" value="Master calculation" />
Thanks very much in advance
From what I understand, only thing you need to do is this, under where you calculate var diff
if(diff < -10 || diff > 10)
alert("diff is more Tham 10");