Solved

Removing Commas from an input text field with Jquery

Posted on 2011-02-10
10
2,891 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
LVL 40

Expert Comment

by:gurvinder372
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:gurvinder372
ID: 34868218
replace if condition contents with

return false;
0
 
LVL 40

Accepted Solution

by:
gurvinder372 earned 500 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:gurvinder372
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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

688 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