Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Removing Commas from an input text field with Jquery

Posted on 2011-02-10
10
Medium Priority
?
3,132 Views
Last Modified: 2012-05-11
I am looking for a solution using Jquery that would mask / remove commas that are inserted into a input (numeric) text field in a form. I have done some research on my own and found a pluggin that does the job http://www.decorplanit.com/plugin/)... unfortunately my understanding of Jquery is limited.

Can someone help me complete the code attached or give me something that I can implement?  I like the idea of using Jquery as it makes the change on the fly and is visual to the end user.

Any thoughts would be greatly appreciated
<!--USED TO REMOVE COMMAS FROM TXT FIELDS http://www.decorplanit.com/plugin/publicFunctions.htm-->
<script src="../../Scripts/jquery-1.4.2.js" type="text/javascript"></SCRIPT>
 <SCRIPT src="../../Scripts/AutoNumberic/jquery.metadata.js" type=text/javascript></SCRIPT> //needed if changing defaults 
<script src="../../Scripts/AutoNumberic/autoNumeric-1.6.2.js" type="text/javascript"></SCRIPT>
<script src="../../Scripts/AutoNumberic/autoLoader.js" type="text/javascript"></SCRIPT>

<script type="text/javascript"> //I don't think the code here is legit
 $(document).ready(function() {
	$.fn.autoNumeric.Strip(dollarvalue, {options} );
 });
</script> 

//// input txt field /////
<input class="strip" type="text" name="dollarvalue" id="dollarvalue" />

Open in new window

0
Comment
Question by:jasch2244
  • 5
  • 4
10 Comments
 
LVL 82

Expert Comment

by:leakim971
ID: 34867779
If by removing you mean don't allow :

Use :
$("#dollarvalue").autoNumeric();

Open in new window


Or :
$.fn.autoNumeric.Strip("#dollarvalue");

Open in new window

0
 
LVL 1

Author Comment

by:jasch2244
ID: 34867871
Yes, I would like to not allow commas to be entered.

Both of the suggestions did not work the second did some formatting for me by adding decimals .00 to the end but that is it... no commas were removed. On the site they mentioned under the strip section that the # signs are to be ommited (http://www.decorplanit.com/plugin/publicFunctions.htm)

Any other suggestions? My new code per your suggestion is attached
<script src="../../Scripts/jquery-1.4.2.js" type="text/javascript"></SCRIPT>
<SCRIPT src="../../Scripts/AutoNumberic/jquery.metadata.js" type=text/javascript></SCRIPT> //needed if changing defaults 
<script src="../../Scripts/AutoNumberic/autoNumeric-1.6.2.js" type="text/javascript"></SCRIPT>
<script src="../../Scripts/AutoNumberic/autoLoader.js" type="text/javascript"></SCRIPT>
<script type="text/javascript"> //I don't think the code here is legit
	 $(document).ready(function() {
		$("dollarvalue").autoNumeric(); 
 });
</script>

Open in new window

0
 
LVL 1

Author Comment

by:jasch2244
ID: 34867924
One other thought I added the $(document).ready(function() and put the other fucntion mentioned on the site in the middle... thinking this was proper. I don't know if it is or not I know that is states once the document is fully loaded do the function contained with in but it might be out of context.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 40

Expert Comment

by:Gurvinder Pal Singh
ID: 34868057
something like this?

 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="javascript">
function checkInput(ob)
{
  if(/,/gi.test(ob.value)) {
        alert("Invalid characters.");
            ob.value = ob.value.substring(0,ob.value.length-1);
      }
}
</script>
</head>

<body>
<textarea onkeyup="checkInput(this)"></textarea>
</body>
</html>
0
 
LVL 1

Author Comment

by:jasch2244
ID: 34868146
Thank you, but no I want it to auto remove as people type and/or paste info into text field.
0
 
LVL 40

Expert Comment

by:Gurvinder Pal Singh
ID: 34868218
replace if condition contents with

return false;
0
 
LVL 40

Accepted Solution

by:
Gurvinder Pal Singh earned 2000 total points
ID: 34868226
or even better

<input type="text" onkeyup="this.value=this.value.replace(',','')" value="" />

0
 
LVL 1

Author Comment

by:jasch2244
ID: 34868250
My coding is aweful can you show me a full example? Sorry
0
 
LVL 40

Expert Comment

by:Gurvinder Pal Singh
ID: 34868252
last one should be enough, please check that one first
0
 
LVL 1

Author Closing Comment

by:jasch2244
ID: 34868254
Easy enough! Thank you
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
The Windows functions GetTickCount and timeGetTime retrieve the number of milliseconds since the system was started. However, the value is stored in a DWORD, which means that it wraps around to zero every 49.7 days. This article shows how to solve t…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…
Suggested Courses

971 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question