JavaScript Scripts





Español Français 中文 Deutsch Portuguese Japanese nederlands
   
 
Free Java Script Codes
Javascript List All
Slide Show Slide Show
Ad Display Ad Display
Image Effect Image Effect
Animated Image Effects Animated Image Effects
Form Validation Form Validation
Color Picker Tool Color Picker Tool
Formatting Forms Formatting Forms
Select All Select All
Dynamic Form Select Dynamic Form select
Dynamic Color Dynamic Color
Calendar Script Calendar
Textbox Counter Textbox Counter
Alphanumeric Alphanumeric
Date Time Script Date & Time
Stop Watch Script Stop Watch script
Delete Repeated Values Delete Repeated Values
Pagination Pagination
Random Generator Random Generator
Animated Text Animated Text
Cursor Position Cursor Position
User Info Window / User Info
Security Security / Authenticate
Bookmark Bookmark
Mouse Effects Mouse Effects
Title Bar Title Bar
Status Bar Status Bar
Country List Country List
Free Games Free Games
Calculators Calculators
 




Convert a Number into Roman Numerals


About
 JavaScript used to convert given numeric values to roman numerals. Simply enter a number in the appropriate space below and click on the Convert button.


Features
a) Used to display the roman value of the given number.
b) Provides easy accessibility.

Preview

Enter the Number:
Roman Value:
©h


Code
Javascript Code
<!-- Script by hscripts.com -->
<!-- Copyright of HIOXINDIA -->
<!-- More scripts @www.hscripts.com -->

<style type="text/css">
.txt{border:1px solid grey;width:150px;height:25px;font-size:12px;padding:5px;}
.fnt{font-size:12px;font-family:arial,verdana;}
</style>

<script type="text/javascript">
function convert_roman()
{
   var narr=new Array("1000000","900000","500000","400000","100000","90000","50000","40000","10000","9000","5000","4000","1000","900","500","400","100","90","50","40","10","9","5","4","1");
   var rarr=new Array("<span style='text-decoration: overline'>M</span>",
                      "<span style='text-decoration: overline'>CM</span>",
                      "<span style='text-decoration: overline'>D</span>",
                      "<span style='text-decoration: overline'>CD</span>",
                      "<span style='text-decoration: overline'>C</span>", 
                      "<span style='text-decoration: overline'>XC</span>",
                      "<span style='text-decoration: overline'>L</span>",
                      "<span style='text-decoration: overline'>XL</span>",
                      "<span style='text-decoration: overline'>X</span>",
                      "<span style='text-decoration: overline'>IX</span>",
                      "<span style='text-decoration: overline'>V</span>",
                      "<span style='text-decoration: overline'>IV</span>",
                      "M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I");
     var num = parseInt(document.getElementById("num").value);
     if(num > 3999999 || num < 1)
     {
       alert("Please enter a number between 1 and 3,999,999");
       return;
     }
     var result = "";
     var chk = num;
     while (chk > 0 )
     {
       var i;
       for (i=0; i<narr.length; i++)
       {
        if(chk >= narr[i] )
        {
          result += rarr[i];
          chk -= narr[i];
          break;
        }
       }
    }
    document.getElementById("res").innerHTML=result; 
}
function isinteger(s)
{
      var i;
      s = s.toString();
      for (i = 0; i < s.length; i++)
      {
         var c = s.charAt(i);
         if (isNaN(c)) 
         {
            alert("Given value is not a number");
            return false;
    }
      }
      return true;
}
</script>
<!-- Script by hscripts.com -->

HTML Code
<table>
<tr><td class="fnt">Enter the Number:</td><td><input type="text" class="txt" id="num" value="" onkeyup="isinteger(this.value); convert_roman();"></td></tr>
<tr><td class="fnt">Roman Value:</td><td class="fnt"><div id="res" style='border:1px solid grey;height:20px; padding: 2px; padding-left: 8px;'></div></td></tr>
<tr><td colspan=2><div align=center style="font-size: 10px; color:green;" id="dumdiv">
<a href="http://www.hscripts.com" id="dum" style="text-decoration:none; color: #dadada;">©h</a>
</div></td></tr>
</table>

Release Date - 06-05-2010
Get free version without ©copyright link for just 5 price

For customization of this script or any script development, contact us at support@hscripts.com


Usage
 a) Copy and paste the javascript code into your HTML page and make use of this.
 b) Here, the function "convert_roman()" is used to convert numeric value to roman numerals.



License
- The javascript (misspelled as java script) is given under GPL License
- i.e. Free use for those who use the codes as it is.
- Free, if your modification does not remove our copyright information and links.
- Click Here for detailed license information.
- You can purchase the script if your requirements does not meet our GPL License terms.
Other Links

web hosting