Results 1 to 6 of 6
Thread: javascript validation
- 05-11-2007, 05:40 AM #1
Member
- Join Date
- Apr 2007
- Location
- Singapore
- Posts
- 29
- Rep Power
- 0
javascript validation
Hi everyone, i have a problem here that i'm not sure how to solve it.
I have the following javascript to check that it is not empty and it is not more than 2000 characters.
When i checked for empty fields, it's ok. But when i checked more than 2000 characters, it can detect the error but when i click submit, it still pop up the confirmation message even when it indicate the field cannot be more than 2000 characters. How do i prevent it? Anyone knows. Please help. Thank you.Java Code:function confirmSubmit() { var obj = document.ResearchPaperForm; var check = false; if (obj.summary.value == ''){ summary.innerHTML = "<span class=fail><bean:message key="alert.msg.publisher.summary.required"/></span>" obj.summary.focus(); check = false; } if (obj.summary.value.length > 2000){ summary.innerHTML = "<span class=fail><bean:message key="alert.msg.publisher.summary.exceed"/></span>" obj.summary.focus(); check = false; }else { check = true; } if (check) { var r = confirm("<bean:message key="alert.msg.publisher.confirm.publish"/>") if (r) { document.ResearchPaperForm.submit(); } else { check = false; } } }
I have another question. If i want to validate the attachment filesize cannot be more than 10MB, how do i do it? Thanks!Last edited by yuchuang; 05-11-2007 at 05:43 AM.
- 05-11-2007, 04:11 PM #2
Member
- Join Date
- Apr 2007
- Location
- Pennsylvania,USA
- Posts
- 45
- Rep Power
- 0
Just curious what this section is doing?
If check is already true at that point why not just submit? What is if(r) doing?Java Code:if (check) { var r = confirm("<bean:messag key="alert.msg.publisher.confirm.publish"/>") if (r) { document.ResearchPaperForm.submit(); } else { check = false; } }
My best method to troubleshoot jasvascript is just put alerts in there as an attempt to step thru the code.
- 05-12-2007, 04:36 PM #3
Member
- Join Date
- Apr 2007
- Location
- Singapore
- Posts
- 29
- Rep Power
- 0
oh, the reason i put that section of the codes is to create a pop up message window to ask the user whether they want to confirm publish. So if r is true then it will submit the form, which is when we click ok at the pop up window. Otherwise, if user clicks cancel, the check is false and nothing will happen.
- 05-13-2007, 04:36 AM #4
Member
- Join Date
- Apr 2007
- Location
- Pennsylvania,USA
- Posts
- 45
- Rep Power
- 0
Well I copied your code to a jsp and it works fine for me. The form submits if the value is not null and does not exceed 2000 characters. I am using firefox.
Try with a different browser and see if it happens. Also firefox has a nice javascript console.
- 05-14-2007, 07:15 AM #5
Member
- Join Date
- Apr 2007
- Location
- Singapore
- Posts
- 29
- Rep Power
- 0
Thanks! But i have another questions. How to use javascript to check the file size of the attachment we uploaded? If i don't use javascript, then can i use java codings to do it? I'm using struts. Anyone knows? Please help. Thank you.
- 05-14-2007, 03:38 PM #6
Member
- Join Date
- Apr 2007
- Location
- Pennsylvania,USA
- Posts
- 45
- Rep Power
- 0
Similar Threads
-
Struts validation
By Jack in forum Web FrameworksReplies: 3Last Post: 10-06-2008, 12:54 AM -
form validation
By abhiN in forum New To JavaReplies: 0Last Post: 03-07-2008, 07:04 AM -
Swing Validation
By ppayal in forum AWT / SwingReplies: 0Last Post: 02-09-2008, 09:00 AM -
Swing validation
By ppayal in forum New To JavaReplies: 0Last Post: 02-09-2008, 08:59 AM -
Another Query On Validation
By Albert in forum Web FrameworksReplies: 1Last Post: 07-05-2007, 06:47 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks