Link to home
Start Free TrialLog in
Avatar of jasch2244
jasch2244

asked on

Removing Commas from an input text field with Jquery

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

Avatar of leakim971
leakim971
Flag of Guadeloupe image

If by removing you mean don't allow :

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

Open in new window


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

Open in new window

Avatar of jasch2244
jasch2244

ASKER

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

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.
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>
Thank you, but no I want it to auto remove as people type and/or paste info into text field.
replace if condition contents with

return false;
ASKER CERTIFIED SOLUTION
Avatar of Gurvinder Pal Singh
Gurvinder Pal Singh
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
My coding is aweful can you show me a full example? Sorry
last one should be enough, please check that one first
Easy enough! Thank you