admin管理员组

文章数量:1287932

I know this is an extremely basic question, but I just couldn't find anything useful on the internet. I have 2 input boxes and I want calculate that input and put the result in output using submit button and navigating by form id.

<script>
function Calculate()
{

  var resources = GetFieldValue( "Resources" );
  var minutes = GetFieldValue( "Minutes" ); 
  var permin = parseFloat(resources) / 60;
  var result = parseFloat(permin) * parseFloat(minutes);
</script>

I know this is an extremely basic question, but I just couldn't find anything useful on the internet. I have 2 input boxes and I want calculate that input and put the result in output using submit button and navigating by form id.

<script>
function Calculate()
{

  var resources = GetFieldValue( "Resources" );
  var minutes = GetFieldValue( "Minutes" ); 
  var permin = parseFloat(resources) / 60;
  var result = parseFloat(permin) * parseFloat(minutes);
</script>
Share Improve this question edited Nov 29, 2012 at 14:15 Sirko 74.1k19 gold badges154 silver badges189 bronze badges asked Nov 29, 2012 at 14:14 AlexAlex 1833 gold badges7 silver badges18 bronze badges 2
  • By submit are you talking about POST submit to the server? and by output you're referring to what? – Robert Koritnik Commented Nov 29, 2012 at 14:16
  • @RobertKoritnik No just a basic run in a html file. – Alex Commented Nov 29, 2012 at 14:24
Add a ment  | 

2 Answers 2

Reset to default 3
<body>
<input type='text' id='Resources'/>
<input type='text' id='Minutes' onblur='Calculate();'/>
<form name ="testarea" Method="Get" Action="youpage.html" id='form1'>
<input type='text' id='answer' name='ans' />
</form>
</body>
<script>


function Calculate()
{
  var resources = document.getElementById('Resources').value;
  var minutes = document.getElementById('Minutes').value; 
  var permin = parseFloat(resources) / 60;
  document.getElementById('answer').value=parseFloat(permin) * parseFloat(minutes);
  document.form1.submit();
}
</script>

Your form will submit and your answer is in the url like

youpage.html?ans=youranswer

Use the HTML button tag : http://www.w3schools./tags/tag_button.asp

<button onClick="Calculate();" value="calculate">

in the function Calculate instead of GetFieldValue use

document.getElementbyId("Resources").value; 

where

<input type="text" id="Resources">

use

document.getElementbyId("Result").value = result;

to fill in another input element.

本文标签: