I am using maskinput.js on an input. When I put a percent sign after the value, when loading the page, nothing is displayed. Without the percent sign, it is displayed. Can anyone let me know what is going on and how to fix it? Thank you
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1" />
<title>Mask</title>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script src="http://yii-framework-tutorial.googlecode.com/svn-history/r3/assets/fb2a00e4/jquery.maskedinput.js" type="text/javascript"></script>
<script>
$(function(){$(".percent").mask("99%");});
$(function(){$(".number").mask("99");});
</script>
</head>
<body>
<input type="text" name="margin" class="percent" value="12" />
<input type="text" name="number" class="number" value="12" />
</body>
</html>
From what I see here, it would appear
masktakes a number, and does not recognize percents as numbers.Solution: Don’t put a percent sign after your number. If the number is somehow generated as a percent, strip out the percent sign with something like
myNumber = myNumber.split("%")[0].