JavaScript Help #13

I'm using the following JavaScript function to force "##-## ##/##" format on the "onkeyup" event attribute of the textbox. How do I make this script also force to enter numeric values while keeping my format.

function force_ftin(field1) {

// Force int values and insert gauge format

var s = field1.value;var slen = s.length;

 

var vkey = window.event.keyCode;

if (vkey == 37 || vkey == 39 || vkey == 8) // allow user to re-postion cursor and use backspace key

return;

 

if (slen == 2)

s += "-";

if (slen == 5)

s += " ";

if (slen == 8)s += "/";

field1.value = s;

}

 Your help is appreciated.

0
sam_asp
4/29/2009 5:57:56 PM
asp.net.client-side 24353 articles. 1 followers. Follow

3 Replies
856 Views

Similar Articles

[PageSpeed] 43

How about using jQuery and an input mask http://www.meiocodigo.com/projects/meiomask/#mm_demos


- William

Please mark the most helpful reply/replies as "Answer".

Give some of my PWSK modules a try.
0
whighfield
4/30/2009 3:51:09 AM
Hello sam_asp
 
In this scenario, I suggest you try to use MaskEdit of AJAX Control Toolkit to achieve the facing goal:
 
MaskedEdit Demonstration
http://www.asp.net/ajax/ajaxcontroltoolkit/samples/maskededit/maskededit.aspx
 
Thanks.

 


Lance Zhang
Microsoft Online Community Support

Please remember to mark the replies as answers if they help and unmark them if they provide no help.
0
Lance
5/4/2009 7:33:26 AM
The thing is I have to use this masking on many textboxes of the web page. To be flexible I want to use javascript instead of AJAX masking controls (which is required one per each control).
0
sam_asp
5/4/2009 1:51:13 PM
Reply:

Similar Artilces:

Need help converting a C#/.NET method into client-side (javascript) function
Hey Guys, I have implemented an AJAX Toolkit CalendarExtender.  I have a method 'CheckDate' in javascript (followed a tut!) that checks to see if the user selected a date > DateTime.Now(). Well, I have a few other things to check but not sure how to do them in javascript, so I'm hoping someone here can help me.  I mean, i can somewhat convert it but it'll be too mangled, I'd rather learn the right way.  I'm attaching the code and any help will be appreciated.  1 protected string CheckDateErrors(string dateGiven) 2 ...

Need help in javascript dropdownlist, redirect page to carry parameters from client side to server side.
Hi experts,   I wrote asp.net web pages for company's portal, however, when I put the pages to the portal, the code conflicts with javascript on autopostback, so that the dropdownlist never do autopostback but give an IE Error: __EventTarget is null or not an object.After I searched the internet, I found people think this is a bug in asp.net 1.1 version.So, I want to change the asp:dropdownlist to a client side javascript control by using <Select><option></option></Select> but I have no experience on javascript.Here is what I want to do, and I need help ...

.Net varible into client side JavaScript
I'm need to get a variable from my web app and place its value in a JavaScript. I tried doing this with a Label but I get the HTML included. I don't think I can use the <%# %> from classic ASP? Anyone have any ideas on how they would approach this problem? tbone_stl wrote:Anyone have any ideas on how they would approach this problem? Hi, and welcome to the ASP.NET forums. It's possible to pass a variable to a javascript function. I created a small coding snippet: <%@ Page Language="C#" %>   <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http...

client-side javascript popup--help
hi all,i am trying to implement this tutorial/code in my web application to show client-side javascript popups alerting the user of various task (ie. updating, inserting and deleting records). the link: http://archive.devnewz.com/devnewz-3-20061129JavaScriptAlertShowmessagefromASPNETCodebehind.html i have come up with the following ASP.NET VB code using ASP 3.5:Imports System.WebImports System.TextImports System.Web.UI''' <summary>''' A JavaScript alert''' </summary>Public Class Alert    ''' <summary>&...

Need help with Javascript for Client side validation
fHi wondering if anyone can help, I need some custom validation on my page to ensure that a user either ticks a checkbox, or enters text into a textbox before they move onto another view. I am using JavaScript for clientside validation. I have the following code, however every time I test it. I get the error: Microsoft JScript runtime error: Object required. Very New to JavaScript and really dunno how to solve this problem. Any help would be much appreciated. Thanks, HayleyFunction IsValid(source, args) { var chkbx2 = document.getElementById("CheckBox2"); var textbox = documen...

Help required in client side javascript validation
Hi All!I am trying to validate input in a textbox entered by user at client side. Input can only either START WITH "35/01" or it can be EQUAL TO "999999999999999". I've written this javascript for this: <script language="javascript" type="text/javascript" > function Validation() { var IMEIString = document.getElementById('<%=txtIMEINo.ClientID %>').value; var subIMEIString = IMEIString.substring(0,5); if( subString == "35/01" || IMEIString == "999999999999999") { } else ...

How to write data to a file in client side using javascript or someother client side scripting language.
Hi, I would like to know how to write a data to a client side file using javascript or someother client side scripting language. The file type expected is ini file. txt file would also be appreciable. Thanks in advance.   If the site is a trusted and you are running IE then you could try http://www.w3schools.com/asp/asp_ref_filesystem.asp The Old Sewing FactoryThat twitter nonsense. You can write to the server, but not to the client's machine.  Being able to do so would be a huge security breach.When you ask a question, remember to click "mark as answered"...

simple javascript / client-side problem
ok, this is pretty simple, but as i have VERY little skill in this area and am on a bit of deadline... any help is greatly appreciated! this form (NoteENTRY.ASPX) POSTS to another form (NoteADMIN.aspx) - and i use ASP.NET Request.Form("txtObject") to read the objects on this form to save to a database. simple. this works fine. i wanted to allow the same NoteADMIN.ASPX form to handle deleting, so i figured i could just have the DELETE button (which is a "SUBMIT" HTML button just like the "SAVE" button) write into a hidden textbox ("txtAction")...

How to use client-side script(javascript) in .Net Remoting
Hi all,     It was known that SAO and Singleton object about .Net Remoting. When I Create an object in server side and hosting in IIS's virtual directory,I want to use javascript asynchronous invoking the remote object by HTTP channel, 80 port and SOAP formatter just like XMLHTTP invoking web service. My code as following, <script>  objXmlDoc = new ActiveXObject("Msxml2.DOMDocument"); objHttp = new ActiveXObject("Msxml2.XMLHTTP"); strEnvelope = ?? objHttp.onreadystatechange = function() { ......  }    szUrl = &...

Perform JavaScript Client Side Confirmation from a VB.NET DataGrid
Hi, I when I delete an item from the database through a Datagrid I want to get a messagebox popingup to give me the choise to Confirm it...in case I clicked the wrong item....the way it works now it just deletes it....can any one help me with an Example I have no Idea how to do this...I found an article in C# but it didnt help me at all. here is my source code <asp:DataGrid ID="dgCustList" Runat="server" AutoGenerateColumns="False" DataKeyField="id" AlternatingItemStyle-BackColor="#F6F6F6" HeaderStyle-BackColor="#C4B58E" CellSpacing="0" CellPadding="2" GridLines="Vertical" Width="100%"...

.net validators + client-side javascript validation, EnableEventValidation=false
Scenario: 1. I have a DropDownList, with 2 listitems in the .aspx. appenddatabound=true and it is tied to a datasource (via datasourceid), autopostback=false, onchange=checkIfAddNew(this) [this is the client side onchange event]The second option on this dropdown is "Add New", and the checkIfAddNew function pops up a new window and when it returns, it adds the newly created option to the dropdown. In order for this to happen without asp.net getting mad, EnableEventValidation has to be set to false in the Page directive. In addition to this dropdownlist, there is a RequiredFieldValidator...

In datawindow.net,access the database from client side event using javascript
In powerbuilder,for example,a datawindow has two columns:itemno,description. input an itemno,validate it.if not found from the database,return 1 to trigger itemerror event; if found,get the description of the item from the database,and fill it into the column "description". The question is how to fulfill the function in web datawindow,through web service? if so,I need an example to realize it. You will need to use AJAX or make a round trip on item change event. -- Dean Jones CEO PowerObjects http://www.powerobjects.com (612) 339-3355 Ext. 112 TeamSybase * *...

How to use client-side script(javascript) in DNA using .Net Remoting
Hi all,     It was known that SAO and Singleton object about .Net Remoting. When I Create an object in server side and hosting in IIS's virtual directory,I want to use javascript asynchronous invoking the remote object by HTTP channel, 80 port and SOAP formatter just like XMLHTTP invoking web service. My code as following, <script> objXmlDoc = new ActiveXObject("Msxml2.DOMDocument"); objHttp = new ActiveXObject("Msxml2.XMLHTTP"); strEnvelope = ?? objHttp.onreadystatechange = function() { ...... }   szUrl = "http://ServerNa...

Please help : question on how to reference web controls from client-side Javascript .
Folks,  I have some simple Javascript here that needs to reference not only aCheckBox object being passed as a parameter, but also various otherfields on my web page. My main question is HOW do I access/manipulate controls withclient-side script ? I know how to access the value of the Checkbox because I pass it to myjavascript function like this : QuoteConv(this) . However, since Asp2.0 renames all the ID properties of my web controls, what's the bestway to reference all the various controls (i.e. html TextBox, checkbox,radio, etc) ???Here's the beginning of my aspx page with...

client side javascript function called from custom validator causes problem. help !
 Hi All. I get the error: Microsoft JScript runtime error: Object expectedBasically, i have a custom validator for a text box. I have set the ClientValidateFunction property to checkNonMandatoryBoxes('1',args) and i have the following javascript function written:  I am not sure why im getting the error. Any ideas?function checkNonMandatoryBoxes(source,args)    {       var element;       switch (source) {       case '1':       element...