Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-11-2007, 06:40 AM
Member
 
Join Date: Apr 2007
Location: Singapore
Posts: 30
yuchuang is on a distinguished road
Send a message via MSN to yuchuang
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.

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; } } }
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.

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 06:43 AM.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 05-11-2007, 05:11 PM
Member
 
Join Date: Apr 2007
Location: Pennsylvania,USA
Posts: 46
sandor is on a distinguished road
Just curious what this section is doing?
Code:
if (check) { var r = confirm("<bean:messag key="alert.msg.publisher.confirm.publish"/>") if (r) { document.ResearchPaperForm.submit(); } else { check = false; } }
If check is already true at that point why not just submit? What is if(r) doing?
My best method to troubleshoot jasvascript is just put alerts in there as an attempt to step thru the code.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 05-12-2007, 05:36 PM
Member
 
Join Date: Apr 2007
Location: Singapore
Posts: 30
yuchuang is on a distinguished road
Send a message via MSN to yuchuang
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.
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 05-13-2007, 05:36 AM
Member
 
Join Date: Apr 2007
Location: Pennsylvania,USA
Posts: 46
sandor is on a distinguished road
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.
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 05-14-2007, 08:15 AM
Member
 
Join Date: Apr 2007
Location: Singapore
Posts: 30
yuchuang is on a distinguished road
Send a message via MSN to yuchuang
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.
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 05-14-2007, 04:38 PM
Member
 
Join Date: Apr 2007
Location: Pennsylvania,USA
Posts: 46
sandor is on a distinguished road
check out the File class, there's a method called length()
File (Java 2 Platform SE v1.4.2)
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
form validation abhiN New To Java 0 03-07-2008 08:04 AM
Swing Validation ppayal AWT / Swing 0 02-09-2008 10:00 AM
Swing validation ppayal New To Java 0 02-09-2008 09:59 AM
Another Query On Validation Albert Web Frameworks 1 07-05-2007 07:47 PM
Struts validation Jack Web Frameworks 2 07-04-2007 04:41 AM


All times are GMT +3. The time now is 03:27 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org