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
When I enter "100" for "weight" and "2" for "height", I receive "0.0002" as the result and this is obviously wrong:
$(document).on('ready page:load', function() {
$('#butt').click(function(){
var hei = $("#hei").val();
var wei = $("#wei").val();
bmi = hei/(wei*wei);
var result = $("#result");
result.html("Your BMI is " + bmi);
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div id="bmi">
<h3>Step 1: Calculating Your Body Mass Index (BMI)</h3>
<form>
<label>Enter Your weight (Kg)</label>
<input type="text" name="weight" id="wei" value="">
<br>
<label>Enter Your height (M):</label>
<input type="text" name="height" id="hei" value="">
<br>
<button type="button" id="butt">Calculate my BMI</button>
<p id="result">Your BMI is </p>
</form>
</div>
The problem isn't the script, but that you swapped your variables;
bmi = hei/(wei*wei);
should be
bmi = wei/(hei*hei);
Your program is correct. Your formula is wrong.
BMI = kg/M^2
So, your formula should be:
bmi = wei/(hei*hei);
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 1 year ago.
Improve this question
I'm adding two numbers, but I am getting NaN in the alert. For example, doing 10+10 returns NaN in the alert. What am doing wrong in this code?
function calcy(){
let a = document.getElementById('in1').Value;
let b = document.getElementById('in2').Value;
let total = parseInt(a) + parseInt(b);
alert(total);
}
<div class="inputs">
<div class="input1">
<input type="text" id="in1">
</div>
<div class="input2">
<input type="text" id="in2">
</div>
</div>
You need to change the .Value to .value;
Try below code :
<script>
function calcy(){
let a = document.getElementById('in1').value;
let b = document.getElementById('in2').value;
console.log("a ="+a);
console.log("b ="+b);
let total = parseInt(a) + parseInt(b);
console.log("total ="+total);
alert(total);
}
</script>
<div class="inputs">
<div class="input1">
<input type="text" id="in1">
</div>
<div class="input2">
<input type="text" id="in2">
</div>
<button onclick="calcy()" >Click</button>
</div>
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 1 year ago.
Improve this question
[![weather app form undefined
GITHUB: https://github.com/mylaconcepts/Weather-Journal-App
When I enter a zip code and how I am feeling into the forms on the webpage it returns undefined in the "Most Recent Entry" position. I am not sure how to start troubleshooting this error.
document.getElementById('generate').addEventListener('click', clickedGenerate);
function clickedGenerate(e) {
e.preventDefault();
const zip = document.getElementById('zip').value;
const content = document.getElementById('feelings').value;
retrieveWeather(baseURL, zip, apiKey)
.then(function (userData){
getData('/add', { date:newDate, temp:userData.main.temp, content})
}).then(function (newData) {
updateUI()
})
</div>
<div class ="holder zip">
<label for="zip">Enter Zipcode here</label>
<input type="text" id="zip" placeholder="enter zip code here">
</div>
<div class ="holder feel">
<label for="feelings">How are you feeling today?</label>
<textarea class= "myInput" id="feelings" placeholder="Enter your feelings here" rows="9" cols="50"></textarea>
<button id="generate" type = "button"> Generate </button>
</div>
<div class ="holder entry">
<div class = "title">Most Recent Entry</div>
<div id = "entryHolder">
<div id = "date"></div>
<div id = "temp"></div>
<div id = "content"></div>
</div>
</div>
</div>
]1]1
retrieveWeather(baseURL, zip, apiKey)
.then(userData => getData('/add', { date:newDate, temp:userData.main.temp, content}))
.then(newData => updateUI())
.catch(err => console.log(err))
you have to return the values in .then() or just use a arrow function to return implicitly.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
Some day ago i'd write for asking what was the problem about onclick event doesn't activate when i clicked in a specific area of the browser. After check a guide i find it the problem end also the rappresentation of my simply test is trivial, i've known the mechanism for activating a particular function in browser text area.
Now that work it... i'd want add more detail of my question...what is the mechanism that activate my function from template html to tag <script></script> ?
<h3> Check is palindrome</h3>
<input type="text" id="input1" >
<input type="text" id="input2">
<br><br>
<input type="button" id="reload" onclick="myFunction()" value="ricarica">
<body >
<p onclick="check()" id="output" style="line-height: 1000px"> TEST</p>
</body>
//WHAT IS THE MECHANISM IN THIS POINT FOR ACTIVATE check()?
<script>
function check() {
var x = document.getElementById("input1").value;
var y = document.getElementById("input2").value;
if(x===y){
document.getElementById("output").innerHTML=" E' PALINDROMA "
}else document.getElementById("output").innerHTML=" NON E' PALINDROMA "";
}
function myFunction() {
location.reload(true);
}
</script>
</html>
Everything about your code is wrong. Like... literally everything. Here's a suggested alternative:
var out = document.getElementById('output');
document.getElementById('input').oninput = function() {
if( this.value.split('').reverse().join('') === this.value) {
out.innerHTML = "The input is a palindrome!";
}
else {
out.innerHTML = "The input is not a palindrome...";
}
};
<input type="text" id="input" />
<p id="output">Type something...</p>
From what I understand, move your check() function to the input field
<input type="text" id="text1" onclick="check()">
and remove from body
<body>
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
So I have a simple app to help a diabetic calculate some different things they would need to help regulate their blood sugar. At the bottom of the page I want to state a few different things as a quick overview. So when I try and pull Carbs down to my list, it doesnt work. What do i do? Code is shown below
<!DOCTYPE HTML>
<html lang="en-us">
<head>
<meta charset="utf-8" name="Austin" content="HTML Code and Java Script">
<title>Title</title>
<script type="text/javascript">
function doseToEat() {
var carbs = parseFloat(document.getElementById("carbs").value);
var insulin = parseFloat(document.getElementById("insulinUnitPer10Carbs").value);
var dose = carbs / (insulin * 10)
document.getElementById("dose").innerHTML = dose;
documnet.getElementById("carbsOutput").innerHTML = carbs;
}
function correction() {
var currentBS = parseFloat(document.getElementById("currentBS").value);
var correction = (currentBS - 100) / 30
document.getElementById("correction").innerHTML = correction;
document.getElementById("currentBSOutput").innerHTML = currentBS;
}
</script>
</head>
<body>
<h3>This Is to help calculate and track your blood sugar.</h3>
<input type="number" id="currentBS">Please Enter your current Blood Sugar.
<br>
<button type="button" onclick="correction()">Calculate Correction</button>
<br>
<label>This is your correction.</label>
<div id="correction"></div>
<br>
<input type="number" id="carbs">How many Carbs will you be eating?
<br>
<input type="number" id="insulinUnitPer10Carbs">How many Units of Insulin do you need per 10 carbs?
<br>
<button type="button" onclick="doseToEat()">Calculate</button>
<br>
<label>This Is How much Insulin you should dose</label>
<div id="dose"></div>
<output type="number" id="time">Time:</output>
<br>
<output type="number" id="Date">Date:</output>
<br>Current Blood Sugar:
<output type="number" id="currentBSOutput"></output>
<br>Carbs:
<output type="number" id="carbsOutput"></output>
<br>
</body>
</html>
You have miss spelled document, need to change this
documnet.getElementById("carbsOutput").innerHTML = carbs;
^------^
to
document.getElementById("carbsOutput").innerHTML = carbs;
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
<html>
<head>
<script>
function testing(){
var search1 = document.forms['tfnewsearch']['search1'].value;
if(search1 == null || search1 == "")
{
alert("Error! Please type in something");
isValid = false;
}
}
</script>
</head>
<form name= id="tfnewsearch" method="post" action="" onsubmit ="return testing();">
<p><input type="text" class="tftextinput" id="search1" size="21" maxlength="120"/>
<input type="submit" value="search" class="tfbutton"/></p>
</form>
<body>
</body>
</html>
so what im trying to do here, is to show an alert pop if user doesnt type anything which is equivalent to null value but i dont understand why it doesnt show the popup. i think theres not error with my function,
http://jsfiddle.net/gYg7r/
Here is how:
JS:
function testing(){
var search1 = document.getElementById('search1').value;
if(search1 == undefined || search1 == ""){
alert("Error! Please type in something");
isValid = false;
}
}
HTML:
<form name="searchForm" id="tfnewsearch" method="post" action="http://google.com" onsubmit ="testing();">
<p><input type="text" class="tftextinput" id="search1" size="21" maxlength="120"/>
<input type="submit" value="search" class="tfbutton"/></p>
</form>