---
title: "Currency Textbox in HTML using JavaScript"  
description: "In this blog I will illustrate a currency format($222.00) textbox using JavaScript with compatible all browser.  $222.00 in this format dollar ‘$’ and"  
author: "Vijay Shukla"  
published: 2012-12-05  
updated: 2014-09-18  
canonical: https://www.mindstick.com/blog/402/currency-textbox-in-html-using-javascript  
category: "javascript"  
tags: ["javascript"]  
reading_time: 2 minutes  

---

# Currency Textbox in HTML using JavaScript

In this blog I will illustrate a [currency format](https://www.mindstick.com/blog/328/currency-format-in-javascript)($222.00) textbox using [JavaScript](https://www.mindstick.com/articles/874/how-to-create-watermark-text-for-textbox-by-using-javascript) with compatible all browser.\

$222.00 in this format dollar ‘$’ and dot ‘.’ Will accept only one time in the textbox and rest of textbox [content](https://www.mindstick.com/articles/13019/get-the-best-content-marketing-pricing-packages-for-your-brand) only numeric.

```
<html><head><script type="text/javascript">function CurrencyFormat(val, id, e) {
        var key = e.keyCode || e.charCode || e.which;        var currentChar = String.fromCharCode(key);        if (e.keyCode == 46 && e.charCode == 0 && e.which == 0) {            $(this).val("");            return true;
        }        if (e.keyCode == 36 && e.charCode == 0 && e.which == 0) {            $(this).val("");            return true;
        }        if (val.indexOf(currentChar) != -1 && currentChar == ".") {            return false;        }       if (val.indexOf(currentChar) != -1 && currentChar == "$") {            return false;        }        if (key >= 48 && key <= 57 || key == 46 || key == 36 || e.keyCode === 8 || e.keyCode === 9 || e.keyCode === 37 || e.keyCode === 35 || e.keyCode === 39) {
            $(this).val("");            return true;
        }
        return false;    }</script></head><body><input type='text' id='t1' onkeypress='return validateForCharacter(value, id, event)' />
</body>
```

In this code have a CurrencyFormat() [method](https://www.mindstick.com/forum/166/webservice-method) which have three parameter.

· Value

· Id

· Event.

Value: is for give the [textbox value](https://www.mindstick.com/forum/33830/how-to-calculate-data-grid-value-and-textbox-value-on-change-in-vb-dot-net-winform) to [function](https://www.mindstick.com/articles/13001/multi-statement-table-valued-user-defined-function-in-sql-server).

Id: is for give the textbox id to function.

Event: id for give the Event to text box.

CurrencyFormat() method will call on onkeypress event.

This [screen](https://www.mindstick.com/forum/33644/loading-screen-during-ajax-call) will appear when show [your code](https://www.mindstick.com/forum/157976/how-can-you-use-jquery-s-testing-framework-such-as-qunit-to-write-unit-tests-for-your-code) on browser.

\
![Currency Textbox in HTML using JavaScript](https://www.mindstick.com/blogs/09052a9c-088d-446e-a496-be6da96e1289/images/dd30c85c-4910-4b52-8747-67eefd484d43.png)

---

Original Source: https://www.mindstick.com/blog/402/currency-textbox-in-html-using-javascript

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
