-
Jscript Validation of text input
I am using Oracle and Tornado. I have the problem that when using the input box for text information that the users can input more text than is available in the oracle field.
Is there some example of jscript validation of text input to limit the number of characters that a user can input into a text box?
Thanks
Mike Becer
-
Input Maxlength
Oracle should not be any different than other DB. The input limit is done via MAXLENGTH in the HTML code. Look at the following sample code. If the code has problem with Oracle then let me know. Note that you must specify Type=TEXT in order to have the MAXLENGTH effective. Here I limit the employeeID field input to be just (1) character.
Using 'tag' is easy and straight forward. If you want to go complex and have full control, you can use dbEditValidateName to scan the input fields and then return true or false for the submit. Check out the examples in the on-line manual. Let me know if you need more examples.
Frank
Dim ed As New Tornado.z
With ed
.dbQP = "U=3|M=g!sysind=t|S=2|D=NWIND|Q=orders|gdf=0,1,2,4 ,8,9,10,11|Ni=b5,update|bm=orders;0"
.dbEditUpdateFlds = "fi=0|ty=ronoup,1,fi=2|ty=text|tag=maxlength=1 "
.dbOptions = "EditTitle = none"
.ASPdbNET()
End With
Last edited by Frank; 05-22-2007 at 12:26 PM.
-
Input Maxlength
Frank,
That works.
I would like to use this function with Textarea instead of text.
Does it work with that?
Thanks
Mike Becker
-
TextArea MaxLength
This is a tricky one !
No, Maxlength does not work with TextArea. You have to do it yourself. See the following example which mixed ASP-db and Js - very powerful. The code limits the entry of the Notes field of the employees table to 15 characters.
Pay attention to a few items -
* Js has a lot of , ; " characters which conflict with the standard ASP-db delimiters. So, set the default delimiters of the property to something else to avoid conflict (+^~) instead of (;,~). Normally these standard delimiters do not show.
* The example is illustrated in the update memo field (Notes).
* My code assumes all your memo fields has < 15 characters. The NWIND example memo has > 15 characters and you'll not able to type anything until you delete the text and re-enter. So adjust your conditions and modify the Js code.
Dim ta As String = "<script language='javascript' type='text/javascript'>" & vbCrLf
ta &= "<!--" & vbCrLf
ta &= "function MaxArea(Obj, MaxLen)" & vbCrLf
ta &= "{" & vbCrLf
ta &= "return (Obj.value.length <= MaxLen);" & vbCrLf
ta &= "}" & vbCrLf
ta &= "-->" & vbCrLf
ta &= "</script>" & vbCrLf
Dim ed As New Tornado.z
With ed
.dbQP = "U=3|M=g!sysind=t|S=2|D=NWIND|Q=employees|Ni=b5,up date|gdf=0,1,2,notes|bm=employees;0"
.dbEditUpdateFlds = "(+^~)fi=0|ty=ronoup^1^fi=notes|ty=textarea|tag=ro ws=5 cols=20 onkeypress='return MaxArea(this, 15);'"
.dbOptions = "EditTitle = none"
.dbSendHead = ta
.ASPdbNET()
End With
Last edited by Frank; 05-30-2007 at 11:27 AM.
-
Javascript
Before anybody get too excited about using Js. Check out the following as a sample of how in some cases, Js might not be a good choice. Essentially, a hecker can peek into your JS and inject their version of the Js and then re-submit the page.
Mozilla Foundation Security Advisory 2005-43
http://www.mozilla.org/security/anno...sa2005-43.html
Frank
Last edited by Frank; 05-27-2007 at 09:53 PM.
-
becoming unstable
Frank,
I have been using this control for a long time and have not run into this yet.
I started using the code you provided but have run into a perplexing problem. I will run code that has worked before but then when I change the tag option in .dbeditupdatefld other pages become unstable and I get the error of
Unbalanced wrapper or Invalid Tag - 9 - 9
Could you please tell me what is going on with this?
Thanks
Mike Becker
-
>>..I have been using this control ...
what control?
>>...I started using the code you provided
Specify what code you have problem? The one in the previous thread? ->
Dim ta As String = "<script language='javascript' type='text/javascript'>" & vbCrLf
ta &= "<!--" & vbCrLf
ta &= "function MaxArea(Obj, MaxLen)" & vbCrLf
ta &= "{" & vbCrLf
ta &= "return (Obj.value.length <= MaxLen);" & vbCrLf
ta &= "}" & vbCrLf
ta &= "-->" & vbCrLf
ta &= "</script>" & vbCrLf
Dim ed As New Tornado.z
With ed
.dbQP = "U=3|M=g!sysind=t|S=2|D=NWIND|Q=employees|Ni=b 5,up date|gdf=0,1,2,notes|bm=employees;0"
.dbEditUpdateFlds = "(+^~)fi=0|ty=ronoup^1^fi=notes|ty=textarea|ta g=ro ws=5 cols=20 onkeypress='return MaxArea(this, 15);'"
.dbOptions = "EditTitle = none"
.dbSendHead = ta
.ASPdbNET()
End With
To make sure - send me your DLL and I'll use the above code to get the error. Remember you have to change the delimiters in order to escape incorrect parsing parsing problem.
Frank
Last edited by Frank; 05-30-2007 at 11:28 AM.
-
reason for problem
Frank,
I meant dll.
It seems that when I add the name='MyArea' to the tag on the.dbEditUpdateFlds that when I post an update it adds [[9]] to the field instead. I am using the (+^~) as you have suggested.
I am using Tornado (Powered by ASPdb.Net) Version : Tornado - (GOLD), ASPdb.Net, ASP-db(tm)(c)1998-2006 by USIntertech Inc. - Ver 6.2.1.0
Thanks
Mike Becker
-
Mike,
send me the code and the DLL (frank@aspdb.com). That is the best way to debug. Leave the DB as NWIND so we both have it.
Frank
-
You have an older version (2003). I retrieved the 2003 code and run the following and it works. Looks like your delimiters may not be appropriate. Simplify your code withproblem and use NWIND as the DB to illustrate the problem.
Frank
Dim ta As String = "<script language='javascript' type='text/javascript'>" & vbCrLf
ta &= "<!--" & vbCrLf
ta &= "function MaxArea(Obj, MaxLen)" & vbCrLf
ta &= "{" & vbCrLf
ta &= "return (Obj.value.length <= MaxLen);" & vbCrLf
ta &= "}" & vbCrLf
ta &= "-->" & vbCrLf
ta &= "</script>" & vbCrLf
Dim ed As New Tornado.Z
With ed
.dbQP = "U=3|S=2|Ni=b5,update|gdf=0,1,2,notes|bm=employees ;0"
.dbMode = "grid"
.dbSQL = "Select * from employees"
.dbDSN = "NWIND"
.dbEditUpdateFlds = "(+^~)fi=0|ty=ronoup^1^fi=notes|ty=textarea|ta g=ro ws=5 cols=20 onkeypress='return MaxArea(this, 15);'"
.dbOptions = "EditTitle = none"
.dbSendHead = ta
'.dbDebug = "activesql"
.ASPdbNET()
End With
Last edited by Frank; 05-30-2007 at 11:28 AM.
-
A bug in the previous code
Do not use Name='xxx' in the tag as it conflicts with the internal unique name assigned to the textarea. Correction already made to the previous code.
Frank
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|