Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3

Thread: Not defined?

  1. #1
    Regular Coder
    Join Date
    Jan 2004
    Location
    Maryland
    Posts
    468
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Not defined?

    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.

    Code:
    <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>

  • #2
    Regular Coder
    Join Date
    Jul 2002
    Location
    Kansas, USA
    Posts
    487
    Thanks
    0
    Thanked 54 Times in 53 Posts
    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.
    Code:
    <script type="text/javascript">
    #2. You have a capital V in a var declaration. Javascript doesn't recognize "Var" as a command.
    Code:
    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.

  • #3
    Regular Coder
    Join Date
    Jan 2004
    Location
    Maryland
    Posts
    468
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks. I knew it had to be something stupid.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •