Solved

Removing Commas from an input text field with Jquery

Posted on 2011-02-10
10
2,745 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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
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…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

831 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