html - javascript one input field connect to several functions -


i'm new programming , have problems. i'would create 1 form (in html , javascript), can calculations. numbers , years. @ first need put input field, can type year (like 2013). input value connected several functions:

  1. calculating difference current year (if ask 2018 should write 5, or if ask 2000 iz shoul write -13 , on...)
  2. check if year leap year (true/false or yes/no, ...)
  3. calculate sum of numbers ask (2018 = 11, 2013=6, ...)
  4. if number prime number (true/false, yes/no, ...)
  5. reverse number (2013 = 3102, 2018=8102, ...)
  6. show chinese zodiac sign year
  7. convert year roman numerals (1=i, 2=ii, 10=x, ...)

i did find function, can't put work. helpful if can this.

examples find on internet:

function isleap() {     var yr = document.getelementbyid("year").value;     if ((parseint(yr) % 4) == 0) {         if (parseint(yr) % 100 == 0) {             if (parseint(yr) % 400 != 0) {                 alert("not leap");                 return "false";             }             if (parseint(yr) % 400 == 0) {                 alert("leap");                 return "true";             }         }         if (parseint(yr) % 100 != 0) {             alert("leap");             return "true";         }     }     if ((parseint(yr) % 4) != 0) {         alert("not leap");         return "false";     } } 

reverse:

<script type="text/javascript">     var year, b = 0;     year= parseint(prompt("enter year: "));      document.write("you've entered: " + year+ "<br />");     while(year> 0) {                 b = b * 10         b = b + parseint(year% 10)         year= parseint(year/ 10)     }     document.write("reverse numbers: ", b);  </script> 

sum numbers:

<script> function find() {     var sum = 0;     var no = parseint(frm.txt1.value);     while (no > 0) {         sum = sum + no % 10;         no = math.floor(no / 10);     }     alert("sum of digits  " + sum); } </script>  <form name="frm">     enter number:<input name="txt1" type="text" />     <input name="b1" onclick="find();" type="button" value="display" /> </form> 

i define functions independent of form input parameter. pass parameter each function , display result wish.

<script type="text/javascript"> function isleap(yr) {     if ((parseint(yr) % 4) == 0) {         if (parseint(yr) % 100 == 0) {             if (parseint(yr) % 400 != 0) {                 return "false";             }             if (parseint(yr) % 400 == 0) {                 return "true";             }         }         if (parseint(yr) % 100 != 0) {             return "true";         }     }     if ((parseint(yr) % 4) != 0) {         return "false";     } }  function reverse(year) {     var b = 0;     year = parseint(year);     while (year > 0) {         b = b * 10         b = b + parseint(year % 10)         year = parseint(year / 10)     }     return b; }  function sum(no) {     var sum = 0;     while (no > 0) {         sum = sum + no % 10;         no = math.floor(no / 10);     }     return sum; }  function outputdata() {     var year = form.year.value;     alert("is leap: " + isleap(year));     alert("reversed: " + reverse(year));     alert("sum: " + sum(year)); } </script>  <form name="form">     enter number:<input name="year" type="text" />     <input name="b1" onclick="outputdata();" type="button" value="display" /> </form> 

Comments

Popular posts from this blog

sql - VB.NET Operand type clash: date is incompatible with int error -

SVG stroke-linecap doesn't work for circles in Firefox? -

python - TypeError: Scalar value for argument 'color' is not numeric in openCV -