...

View Full Version : Not defined?



squirellplaying
03-13-2004, 08:16 PM
In my code it says "findIdealGas" is not defined. But it should be! I have that line in two places. A function findIdealGas(){} , and in an onclick="findIdealGas()". I don't know whats wrong with it. It's probably something dumb I know it. But I can't find it.



<html>
<head>
<script language = 'text/javascript'>
function findIdealGas(){
if (document.getElementById('findMole').checked){
findMole()
return(true)
} //closes first if
if (document.getElementById('findVolume').checked){
findVolume()
return(true)
} //closes second if
if (document.getElementById('findPressure').checked){
findPressure()
return(true)
} //closes third if
if (document.getElementById('findTemperature').checked){
findTemperature()
return(true)
} //closes fourth if
else{
alert('Please select what to solve for.')
return(false)
} //closes else


} //closes function


function findMole(){
var P = document.getElementById('pressure').value;
var V = document.getElementById('volume').value;
var T = document.getElementById('temperature').value;
var R = 8.31;
var N = (parseFloat(P)*parseFloat(V))/(parseFloat(R)*parseFloat(T));
document.getElementById('answer').innerHTML = 'Moles:' + N;
}

function findVolume(){
var P = document.getElementById('pressure').value;
var N = document.getElementById('mole').value;
var T = document.getElementById('temperature').value;
var R = 8.31;
Var V = (parseFloat(N)*parseFloat(R)*parseFloat(T))/parseFloat(P);
document.getElementById('answer').innerHTML = 'The volume is:' + V;
}

function findPressure(){
var N = document.getElementById('mole').value;
var V = document.getElementById('volume').value;
var T = document.getElementById('temperature').value;
var R = 8.31;
var P = (parseFloat(N)*parseFloat(R)*parseFloat(T))/parseFloat(V);
document.getElementById('answer').innerHTML = 'The pressure is:' + P;
}

function findTemperature(){
var P = document.getElementById('pressure').value;
var V = document.getElementById('volume').value;
var N = document.getElementById('mole').value;
var R = 8.31;
var T = (parseFloat(P)*parseFloat(V))/(parseFloat(N)*parseFloat(R));
document.getElementById('answer').innerHTML = 'The temperature is:' + P;
}

</script>
</head>

<body>
Find Moles<input type="radio" name="which" id="findMole" />
Find Volume<input type="radio" name="which" id="findVolume" />
find Pressure<input type="radio" name="which" id="findPressure" />
Find Temperature<input type="radio" name="which" id="findTemperature" />
<br />
<br />
Pressure:<input type="text" id="pressure" />
<br />
Volume:<input type="text" id="volume" />
<br />
Temperature:<input type="text" id="temperature" />
<br />
Moles:<input type="text" id="mole" />
<br/>
<input type="button" value="Get the answer" onclick="findIdealGas()" />
<Br />
<br />
<span id="answer"></span>
</body>
</html>

kansel
03-13-2004, 11:17 PM
You have two coding problems that are preventing the script from running.

#1. Your <script> tag is invalid. The language attribute is no longer used and "text/javascript" is not a valid language designation anyhow.

<script type="text/javascript">

#2. You have a capital V in a var declaration. Javascript doesn't recognize "Var" as a command.

function findVolume(){
var P = document.getElementById('pressure').value;
var N = document.getElementById('mole').value;
var T = document.getElementById('temperature').value;
var R = 8.31;
var V = (parseFloat(N)*parseFloat(R)*parseFloat(T))/parseFloat(P);
document.getElementById('answer').innerHTML = 'The volume is:' + V;
}

Correcting these allows the script to run normally.

squirellplaying
03-13-2004, 11:34 PM
Thanks. I knew it had to be something stupid. :(



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum