Value will blink only once at the html text box

Mars

while loop in javascript

function calc(){
var one = document.getElementById("fv").value;
var two = document.getElementById("sv").value;
var one1 = parseInt(one); 
var two1 = parseInt(two);
var total = 0;
if(one1<=two1){
while (one1 <= two1){
total = total+one1;
one1++;                         
total=total;
}
document.getElementById("tv").value = total;
}}
calc() //call function
</script>
<form>

There are some confusion using while loop in java script. can i use while loop for those type of calculation?

<p>"Calculation of sum between two numbers"</p>
<h5>First Number</h5><input type ="text" value="1" name="firstv" id="fv"><br>
<h5>Second Number</h5><input type="text" value="100" name="sectv" id="sv"><br>
<h5>Value</h5><input type="number" value= "" name="tv" id="tv"><br>
<button onclick="calc()" value="click">Calculate</button><br>
</form>
</body>
</html>
Pete

You need to stop the button from actually submitting the form. If you make sure that your Javascript function appears before your html and your button looks like this:

<button onclick="calc(); return false;" value="click">Calculate</button>

Then it should work properly

If you need to call the first calc() before the button is clicked, you need to do it when the document is ready:

document.addEventListener("DOMContentLoaded", function(event) { 
   calc();
});

Example

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

Get the value in an input text box

From Dev

The value of the text box prints as Undefined

From Dev

jQuery - Text toggles only once

From Dev

Once checkbox is checked auto select text box

From Dev

Unable to display value in HTML text input box

From Dev

How do I make the text input box cursor blink automatically when the page loads?

From Dev

HTML only posts last text box for text form

From Dev

Input box text value trick

From Dev

Enter the value in text box with JavaScript in HTML

From Dev

How to display only the text in datalist HTML5 and not the value?

From Dev

Make placeholder text inside html text field blink

From Dev

On Error GoTo only working once for analyzing input box value

From Dev

Pass Search value from one html page text box to another html page text box on click using cookies?

From Dev

text box only displaying one word as value

From Dev

processing immediate text box value

From Dev

How to populate the value of a Text Box based on the value in a Combo Box in a html page

From Dev

How do I display and calculate average ? And how do I write the value to the text file only once?

From Dev

Comment Box add text value without html

From Dev

Returning a value to a text box with JavaScript

From Dev

Passing Text box value into string

From Dev

Text associated with a read only text box not shown in the HTML

From Dev

Enter the value in text box with JavaScript in HTML

From Dev

In the html text box, how to show value which itself contains "" symbol?

From Dev

Value will blink only once at the html text box

From Dev

Make placeholder text inside html text field blink

From Dev

Blink only specific text

From Dev

JavaScript not executing text-box value in HTML

From Dev

Write value from text box into cell only if textbox is not empty

From Dev

Increment Value of Span only once

Related Related

  1. 1

    Get the value in an input text box

  2. 2

    The value of the text box prints as Undefined

  3. 3

    jQuery - Text toggles only once

  4. 4

    Once checkbox is checked auto select text box

  5. 5

    Unable to display value in HTML text input box

  6. 6

    How do I make the text input box cursor blink automatically when the page loads?

  7. 7

    HTML only posts last text box for text form

  8. 8

    Input box text value trick

  9. 9

    Enter the value in text box with JavaScript in HTML

  10. 10

    How to display only the text in datalist HTML5 and not the value?

  11. 11

    Make placeholder text inside html text field blink

  12. 12

    On Error GoTo only working once for analyzing input box value

  13. 13

    Pass Search value from one html page text box to another html page text box on click using cookies?

  14. 14

    text box only displaying one word as value

  15. 15

    processing immediate text box value

  16. 16

    How to populate the value of a Text Box based on the value in a Combo Box in a html page

  17. 17

    How do I display and calculate average ? And how do I write the value to the text file only once?

  18. 18

    Comment Box add text value without html

  19. 19

    Returning a value to a text box with JavaScript

  20. 20

    Passing Text box value into string

  21. 21

    Text associated with a read only text box not shown in the HTML

  22. 22

    Enter the value in text box with JavaScript in HTML

  23. 23

    In the html text box, how to show value which itself contains "" symbol?

  24. 24

    Value will blink only once at the html text box

  25. 25

    Make placeholder text inside html text field blink

  26. 26

    Blink only specific text

  27. 27

    JavaScript not executing text-box value in HTML

  28. 28

    Write value from text box into cell only if textbox is not empty

  29. 29

    Increment Value of Span only once

HotTag

Archive