Reputation: 183
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>
Upvotes: 0
Views: 41577
Reputation: 5868
Use the HTML button tag : http://www.w3schools.com/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.
Upvotes: 1
Reputation: 3005
<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
Upvotes: 3