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
2 Answers
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.
本文标签:
版权声明:本文标题:javascript - How to calculate two input form fields and put the value in another using JS and submit button? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741324166a2372378.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论