Free Java Script Codes
List All
Slide Show
Ad Display
Image Effect
Animated Image Effects
Form Validation
Color Picker Tool
Formatting Forms
Select All
Dynamic Form select
Dynamic Color
Calendar
Textbox Counter
Alphanumeric
Date & Time
Stop Watch script
Delete Repeated Values
Pagination
Random Generator
Animated Text
Cursor Position
Window / User Info
Security / Authenticate
Bookmark
Mouse Effects
Title Bar
Status Bar
Country List
Free Games
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.
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
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.