Athmaus
03-17-2005, 10:55 AM
I know in html you can set a "max" character limit for a form field. I was wondering if it is possible to set a min number of characters? I need it to be in a popup box after they hit the submit button. Any ideas?
|
Click to See Complete Forum and Search --> : Min Form Field Limit? Athmaus 03-17-2005, 10:55 AM I know in html you can set a "max" character limit for a form field. I was wondering if it is possible to set a min number of characters? I need it to be in a popup box after they hit the submit button. Any ideas? phpnovice 03-17-2005, 12:19 PM JavaScript can do this -- or, go ahead and submit the form to the server. Then, on the return trip, in addition to HTML changes to indicate the error, your server-side code can insert the JavaScript to also pop up an alert for the error. JavaScript may be disabled at the client. That is why I am making this suggestion. JavaScript: <input ... onchange=" if(this.value.length < 3) { alert('Three or more characters are required.'); this.select(); this.focus(); return false; } return true;"> Athmaus 03-17-2005, 12:27 PM I was about to say that ASP won't work after looking into it more. I'm sorry i know jack about javascript. That is not the complete code is it? I just need to read taht a form entry (named "Order") has at least 8 characters in it. If it doesnt a popup box occurs saying somthign, with an "ok" button. When they press that they are still on the form page to re enter the order number phpnovice 03-17-2005, 01:06 PM That is the complete JavaScript code, yes. Just change the 3/three to an 8/eight. The HTML part is abbreviated with an elipsis (...), but that JavaScript code will work for any INPUT tag to which you care to apply it. You can also code it this way to make sure JavaScript is explicitly invoked: <input ... onchange="javascript: if(this.value.length < 3) { alert('Three or more characters are required.'); this.select(); this.focus(); return false; } return true;"> Athmaus 03-17-2005, 01:17 PM dude you are my hero!!!! Thank you soooooooooooooooo much! :D Athmaus 03-17-2005, 02:58 PM hey can i please ask one more favor? I have to put in a range now (dont you love when people keep changing the rules as they go along?) I am trying to edit the javascript so that if it is less than 8 it gives that error andit if is more than 11 it gives same error. ANy ideas? I thank you for your patience and help you have provided thus far. phpnovice 03-17-2005, 03:29 PM No problem: if(this.value.length < 8 || this.value.length > 11) { Athmaus 03-17-2005, 03:34 PM thank you once more i really appreciate it! i guiess i need to get me a javascript book ^_^ phpnovice 03-17-2005, 03:44 PM Cheers. JScript References (http://msdn.microsoft.com/library/en-us/script56/html/js56jsoriJScript.asp) webdeveloper.com
Copyright Internet.com Inc., All Rights Reserved. |