By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
426,034 Members | 1,672 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 426,034 IT Pros & Developers. It's quick & easy.

onclick not working properly with <html:submit>

100+
P: 283
hi frnds,
i have a form,which has 2 input text boxes, the values are entering the text boxes,when i leave the 2 text boxes blank and hit submit a java script gives the message that the 2 fields are blank.....the problem now is when i leave the text boxes blank the message appears...and when i click ok...then instead of showing me the page its giving me an exception-->
type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

javax.servlet.ServletException: Incorrect integer value: '' for column 'Publicity_Code' at row 1
org.apache.struts.action.RequestProcessor.processE xception(RequestProcessor.java:545)
org.apache.struts.action.RequestProcessor.processA ctionPerform(RequestProcessor.java:486)
org.apache.struts.action.RequestProcessor.process( RequestProcessor.java:274)
org.apache.struts.action.ActionServlet.process(Act ionServlet.java:1482)
org.apache.struts.action.ActionServlet.doGet(Actio nServlet.java:507)
javax.servlet.http.HttpServlet.service(HttpServlet .java:690)
javax.servlet.http.HttpServlet.service(HttpServlet .java:803)


root cause

java.sql.SQLException: Incorrect integer value: '' for column 'Publicity_Code' at row 1
com.mysql.jdbc.SQLError.createSQLException(SQLErro r.java:946)
com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.ja va:2985)
com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:16 31)
com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java :1723)
com.mysql.jdbc.Connection.execSQL(Connection.java: 3256)
com.mysql.jdbc.PreparedStatement.executeInternal(P reparedStatement.java:1313)
com.mysql.jdbc.PreparedStatement.executeUpdate(Pre paredStatement.java:1585)
com.mysql.jdbc.PreparedStatement.executeUpdate(Pre paredStatement.java:1500)
com.mysql.jdbc.PreparedStatement.executeUpdate(Pre paredStatement.java:1485)
org.apache.tomcat.dbcp.dbcp.DelegatingPreparedStat ement.executeUpdate(DelegatingPreparedStatement.ja va:101)
publicity.BdgtMastAction.execute(BdgtMastAction.ja va:57)
org.apache.struts.action.RequestProcessor.processA ctionPerform(RequestProcessor.java:484)
org.apache.struts.action.RequestProcessor.process( RequestProcessor.java:274)
org.apache.struts.action.ActionServlet.process(Act ionServlet.java:1482)
org.apache.struts.action.ActionServlet.doGet(Actio nServlet.java:507)
javax.servlet.http.HttpServlet.service(HttpServlet .java:690)
javax.servlet.http.HttpServlet.service(HttpServlet .java:803)
--------------------------------------------------------------------------------

Apache Tomcat

y is this happening??
im using struts tags-->
Expand|Select|Wrap|Line Numbers
  1. <html:submit value="Submit" property="thesubmit" onclick="everything(form)">&nbsp;</html:submit>
but when i do it using normal html tags its working perfectly alright--->
Expand|Select|Wrap|Line Numbers
  1. <input type="button" name="thesubmit" value="Submit" onclick="everything(form)">&nbsp;
can somebdy plz help me???
regards,
ajos
Sep 26 '07 #1
Share this Question
Share on Google+
31 Replies


100+
P: 283
guys still no solution....plz help..even with the conventional
Expand|Select|Wrap|Line Numbers
  1. <input type="button" name="thesubmit" value="Submit" onclick="everything(form)">&nbsp;
only the java script validation part is getting checked...the values is not getting inserted.....plz help
Sep 26 '07 #2

acoder
Expert Mod 15k+
P: 16,027
Show your form HTML and Javascript validation code.
Sep 26 '07 #3

100+
P: 283
Show your form HTML and Javascript validation code.
hi thanx for the response
herz my jsp-->
[HTML]
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<html:html>
<head>
<title>Budget Master Administration</title>
<meta name="GENERATOR" content="Microsoft FrontPage 3.0">
<SCRIPT LANGUAGE="JavaScript" SRC="bscript.js"></SCRIPT>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
</head>
<body topmargin="0" leftmargin="0" bgproperties="fixed">
<div align="left">
<html:form action="/BdgtMastAction" name="bdgtmastForm" type="publicity.BdgtMastForm" method="get">
<table border="0" width="100%">
<tr>
<td width="100%" bgcolor="#DFDFFF" background="images/niceblue.gif"><font face="Tahoma"
color="#000000"><strong>B u d g e t&nbsp;&nbsp; M a s t e r</strong></font></td>
</tr>
</table>
<div align="left">

<table width="60%" height="127">
<tr>
<td valign="top" width="50%" height="34"><strong><small><font face="Verdana"></font></small></strong></td>
<td width="50%" height="34"></td>
</tr>
<tr>
<td valign="top" width="50%" height="27"><strong><small><font face="Verdana">Branch</font></small></strong></td>
<td width="50%" height="27">

<html:hidden name="bdgtmastForm" property="option" value="new"/>
<p>
<html:select property="branch" size="1">

<html:option value="Bombay"></html:option>
<html:option value="Ahmedabad"></html:option>
<html:option value="Madras"></html:option>
<html:option value="Bangalore"></html:option>
<html:option value="Calcutta"></html:option>
<html:option value="Hyderabad"></html:option>
<html:option value="Pune"></html:option>
<html:option value="Lucknow"></html:option>
<html:option value="Jaipur"></html:option>
<html:option value="Patna"></html:option>
<html:option value="Cochin"></html:option>
<html:option value="Chandigarh"></html:option>
<html:option value="Bhopal"></html:option>


</html:select>
</p>
</td>
</tr>
<tr>
<td width="50%" height="25"><strong><small><font face="Verdana">Publicity Code </font></small></strong></td>
<td width="50%" height="25">
<html:text name="bdgtmastForm" property="publicity_Code" size="5" maxlength="5"></html:text>

</tr>
<tr>
<td width="50%" height="25"><strong><small><font face="Verdana">Annual Budget Alloted (<em>Rs</em>)</font></small></strong></td>
<td width="50%" height="25">
<html:text property="budget" name="bdgtmastForm" size="10" maxlength="10" ></html:text>
</td>
</tr>
</table>
</div>

<p align="left">
<!-- <html:button property="thesubmit" value="Submit" onclick="everything(form)"></html:button> -->
<html:submit value="Submit" property="thesubmit" onclick="everything(form)">&nbsp;</html:submit>
<!-- <input type="button" name="thesubmit" value="Submit" onclick="everything(form)">&nbsp; -->
</p>

<hr>
<strong><small><font color="#0080C0">
<p align="center"></font><font color="#0080C0" face="Verdana">Response - Corporate
1998-1999</font></small></strong>
</html:form>
</div>
</body>
</html:html>
[/HTML]

herz my java script-->
Expand|Select|Wrap|Line Numbers
  1. function everything(form) {
  2. isbudget(form)
  3. iscode(form)
  4. allblanks(form) 
  5. }
  6.  
  7. function allblanks(form) 
  8. {
  9.  if(isbudget(form) && iscode(form)) 
  10.  {
  11.    arch.submit() 
  12.  }
  13.  if(isbudget(form) == false || iscode(form) == false) 
  14.  {
  15.   compose(form)
  16.  }
  17. }
  18.  
  19. function compose(form) {
  20.   var text = "You forgot to fill in correctly:" 
  21.   var text1 = " Or Value Entered is Not Valid"  
  22.   if(isbudget(form) == false) {
  23.    text += "\nBUDGET ALLOTED"
  24.    text +=text1
  25.   }
  26.  
  27.   if (iscode(form) == false) {
  28.    text += "\nPUBLICITY CODE"
  29.    text +=text1
  30.   }
  31.   alert(text)
  32. }
  33.  
  34.  
  35. function isbudget(form)
  36. {
  37.  if (form.budget.value == "") {
  38.   return false
  39.  }
  40.  else {
  41.   var len = form.budget.value.length
  42.   for (var k = 0; k < len; k++)
  43.   {
  44.     var c = form.budget.value.substring(k, k+1);
  45.     if(c != ".") 
  46.     {
  47.      if(isNaN(parseFloat(c))) 
  48.      {
  49.       return false
  50.      }
  51.     } 
  52.   }
  53.   return true
  54.  }
  55. }
  56.  
  57.  
  58. function iscode(form)
  59. {
  60.  if (form.publicity_Code.value == "") {
  61.   return false
  62.  }
  63.  else {
  64.   var len = form.publicity_Code.value.length
  65.   for (var k = 0; k < len; k++)
  66.   {
  67.     var c = form.publicity_Code.value.substring(k, k+1);
  68.      if(isNaN(parseFloat(c))) 
  69.      {
  70.       return false
  71.      }
  72.   }
  73.   return true
  74.  }
  75. }
  76.  
  77.  
thanx in advance.
regards
ajos
Sep 26 '07 #4

acoder
Expert Mod 15k+
P: 16,027
Rather than using the submit button's onclick, use the form element's onsubmit:
[HTML]<form ... onsubmit="return everything(this);">[/HTML]

Don't forget that you have to return true or false depending on whether it validated correctly or not.

One final thing: your call to iscode() and isbudget() is redundant in everything() because you check it again in allblanks().
Sep 26 '07 #5

100+
P: 283
Rather than using the submit button's onclick, use the form element's onsubmit:
[HTML]<form ... onsubmit="return everything(this);">[/HTML]

Don't forget that you have to return true or false depending on whether it validated correctly or not.

One final thing: your call to iscode() and isbudget() is redundant in everything() because you check it again in allblanks().
thanx for the reply,
i even did wat u said--->
[HTML]<html:form action="/BdgtMastAction" name="bdgtmastForm" type="publicity.BdgtMastForm" method="get" onsubmit="return everything(this);">[/HTML]
but that didnt help it....the problem is when i click on submit without entering the values the js validation says to enter the values, and when i click on ok ...an exception page shows up saying that the enteries should not be null.
u had said to return true or false....where do i mention it???
regards,
ajos
Sep 26 '07 #6

acoder
Expert Mod 15k+
P: 16,027
u had said to return true or false....where do i mention it???
In function allblanks(), when the validation passes, return true rather than submit the form. When it fails, after compose(), put in return false.
Sep 26 '07 #7

100+
P: 283
In function allblanks(), when the validation passes, return true rather than submit the form. When it fails, after compose(), put in return false.
hi thanx acoder for the reply,
that didnt work either....:(
how will i know where im going wrong...coz i got no clue of it...im converting the html in to jsp using struts taglibs....before this i was able to run it smoothly using plain html....confused!!
regards,
ajos
Sep 26 '07 #8

acoder
Expert Mod 15k+
P: 16,027
Show your updated Javascript code.

It would also be useful to see your generated HTML code (view source in the browser).
Sep 26 '07 #9

100+
P: 283
Show your updated Javascript code.

It would also be useful to see your generated HTML code (view source in the browser).
my updated js code(allblanks)
Expand|Select|Wrap|Line Numbers
  1. function allblanks(form) 
  2. {
  3.  if(isbudget(form) && iscode(form)) 
  4.  {
  5.    return true
  6.  }
  7.  if(isbudget(form) == false || iscode(form) == false) 
  8.  {
  9.   compose(form)
  10.   return false
  11.  }
  12. }
  13.  
and my html is --->
[HTML]<html:form action="/BdgtMastAction" name="bdgtmastForm" type="publicity.BdgtMastForm" method="get" onsubmit="return everything(this);">[/HTML]

[HTML] <html:submit value="Submit" property="thesubmit">&nbsp;</html:submit> [/HTML]

when i use this instead-->
[HTML]<html:button property="thesubmit" value="Submit" onclick="everything(form)"></html:button>[/HTML]
the validation is successful i.e the scripting tells me that the text field is blank...
but it dsnt submits the values....
regards,
ajos
Sep 26 '07 #10

acoder
Expert Mod 15k+
P: 16,027
and my html is --->
[HTML]<html:form action="/BdgtMastAction" name="bdgtmastForm" type="publicity.BdgtMastForm" method="get" onsubmit="return everything(this);">[/HTML]
What does look like in normal HTML? By that, I mean something like:
[HTML]<form action="/BdgtMastAction" name="bdgtmastForm" method="get" onsubmit="return everything(this);">[/HTML]with no JSP.

Have you removed isbudget() and iscode() from everything(). These will return true or false preventing the rest of the code from executing.
Sep 26 '07 #11

100+
P: 283
What does look like in normal HTML? By that, I mean something like:
[HTML]<form action="/BdgtMastAction" name="bdgtmastForm" method="get" onsubmit="return everything(this);">[/HTML]with no JSP.
.
when i try to right click the page ond click on view source code nothing happens...how will i activate the view source code option?

Have you removed isbudget() and iscode() from everything(). These will return true or false preventing the rest of the code from executing
.
isbudget() and iscode() which is in the everything() method is the main validation..if i remove that part then the validation will fail....
still no soln for me:(
regards,
ajos
Sep 27 '07 #12

acoder
Expert Mod 15k+
P: 16,027
when i try to right click the page ond click on view source code nothing happens...how will i activate the view source code option?
Try View Source from the browser's View menu.
isbudget() and iscode() which is in the everything() method is the main validation..if i remove that part then the validation will fail....
isbudget() and iscode() is called in allblanks(), so there is no need to call them in everything(). In fact, that's preventing allblanks() from being run.

In allblanks(), you're calling both functions twice when you could just set the return values to 2 variables and make the checks against them.
Sep 27 '07 #13

100+
P: 283
Try View Source from the browser's View menu.
i tried that but cant view the source...
isbudget() and iscode() is called in allblanks(), so there is no need to call them in everything(). In fact, that's preventing allblanks() from being run.
i did this like u said-->

Expand|Select|Wrap|Line Numbers
  1. function everything(form) {
  2. allblanks(form) 
  3. }
  4. function everything(form) {
  5.  
  6. allblanks(form) 
  7. }
  8.  
  9. function allblanks(form) 
  10. {
  11.  if(isbudget(form) && iscode(form)) 
  12.  {
  13.       return true
  14.  }
  15.  if(isbudget(form) == false || iscode(form) == false) 
  16.  {
  17.   compose(form)
  18.   return false
  19.  }
  20. }
  21.  
  22.  
i removed the isbudget and iscode even that didnt work....but how is it possible that this thing is not working coz it was working well when i did it using jsp...y is it not working when trying it using struts1.1??
regards,
ajos
Sep 27 '07 #14

acoder
Expert Mod 15k+
P: 16,027
but how is it possible that this thing is not working coz it was working well when i did it using jsp...y is it not working when trying it using struts1.1??
Hmm.. I've never used struts, so I'm not sure what the problem might be. Can you put up a test page and link to it?
Sep 27 '07 #15

100+
P: 283
Hi friends,
I have a javascript code which was working well with my plain html properly, but now the issue is ever since i embeded that script in my jsp page(im working with struts) it stopped working. I cant figure out what the problem might be. What happens specifically is, when i click on submit the javascript doesnt fire up(it used to fire previously in html page.) Please help me regarding this problem.
the javascript code goes--->
Expand|Select|Wrap|Line Numbers
  1. function setdate1(form) {
  2. var now = new Date();
  3. var date = now.getDate();
  4. var month = now.getMonth();
  5. var year = now.getFullYear();
  6. //var year = now.getYear();
  7. newyear = year
  8. newmonth = month+1;
  9. var date1 = date+"/"+newmonth+"/"+newyear;
  10. document.arch.date.value=date1;
  11. document.arch.approved_by.value="Neeta Asnani";
  12. }
  13.  
  14. function everything(form) {
  15. isdate(form)
  16. isbrief(form)
  17. isdigit(form)
  18. isperiod(form)
  19. isproposed(form)
  20. isapprove(form)
  21. allblanks(form)
  22. }
  23.  
  24. function allblanks(form) 
  25. {
  26.  if(isdate(form) && isbrief(form) && isperiod(form) && isproposed(form)  && isapprove(form) && isdigit(form)) 
  27.  {
  28.    form.submit() 
  29.  }
  30.  if(isdate(form) == false || isbrief(form) == false ||       
  31.    isperiod(form) == false || isproposed(form) == false || isapprove(form) == false || isdigit(form) == false) 
  32.  {
  33.   compose(form)
  34.  }
  35. }
  36.  
  37. function compose(form) {
  38.   var text = "You forgot to fill in correctly:"    
  39.   if(isdate(form) == false) {
  40.    text += "\nDATE"
  41.   }
  42.  
  43.   if (isbrief(form) == false) {
  44.    text += "\nBRIEF FOR CREATIVE"
  45.   }
  46.   if (isperiod(form) == false) {
  47.    text += "\nPERIOD OF PUBLICITY"
  48.   }
  49.   if (isproposed(form) == false) {
  50.    text += "\nPROPOSED BY"
  51.   }
  52.   if (isapprove(form) == false) {
  53.    text += "\nAPPROVED BY"
  54.   }
  55.   if (isdigit(form) == false) {
  56.    text += "\nAMOUNT"
  57.   }
  58.  
  59.  
  60. alert(text)
  61. }
  62.  
  63. function isdate(form)
  64. {
  65.   if (form.date.value == "") {
  66.   return false
  67.   }
  68.   else {
  69.   var len = form.date.value.length
  70.   for (var k = 0; k < len; k++)
  71.   {
  72.     var c = form.date.value.substring(k, k+1);
  73.     if(c != "/") 
  74.     {
  75.      if(isNaN(parseInt(c))) 
  76.      {
  77.       return false
  78.      }
  79.     } 
  80.   }
  81.  
  82.    if(len > 10) {return false}
  83.    if(len < 8) {return false}
  84.    if(len == 10) 
  85.    {
  86.     var n2 =form.date.value.substring(6,10)
  87.     if (n2 != newyear) {return false}
  88.    }
  89.  
  90.    if(len == 9) 
  91.    {
  92.     var n3 =form.date.value.substring(5,9)
  93.     if (n3 != newyear) {return false}
  94.    }
  95.    if (len == 8)
  96.    { var n3 = form.date.value.substring(4,8)
  97.      if (n3 != newyear) {return false}
  98.    }
  99.    return true
  100.   }
  101. }
  102.  
  103. function isbrief(form)
  104. {
  105.  if (form.brief1.value == "") {
  106.   return false
  107.  }
  108.  else {
  109.   return true
  110.  }
  111. }
  112. function isperiod(form)
  113. {
  114.  if (form.period.value == "") {
  115.   return false 
  116.  }
  117.  else {
  118.   return true
  119.  }
  120. }
  121. function isproposed(form)
  122. {
  123.    if (form.proposed_by.value == "") {
  124.     return false
  125.    }
  126.    else {
  127.    return true
  128.    }
  129. }
  130.  
  131. function isapprove(form)
  132. {
  133.  if (form.approved_by.value == "") {
  134.    return false 
  135.  }
  136.  else {
  137.    return true
  138.  }
  139. }
  140.  
  141. function isdigit(form)
  142. {
  143.  if(form.amount.value == "")
  144.  {
  145.  return false;
  146.  }
  147.  else
  148.  {
  149.   var len = form.amount.value.length
  150.   var test = ""+form.amount.value;
  151.   for (var k = 0; k < len; k++)
  152.   {
  153.     var ch = test.substring(k, k+1);
  154.     if(ch != ".") 
  155.     {
  156.      if(isNaN(parseFloat(ch))) 
  157.      {
  158.       return false
  159.      }
  160.     } 
  161.   }
  162.   return true
  163.  }
  164. }
  165.  
  166.  
  167.  
and my jsp page is--->This is not the complete code.

[HTML]
<SCRIPT LANGUAGE="JavaScript" SRC="reqscript1.js"></SCRIPT> <html:form action="/ExpenReqAction" name="expenreqForm" type="publicity.ExpenReqForm" method="post" onsubmit="return everything(this);">

<html:submit value="Submit" property="thesubmit"></html:submit>
<html:reset value="Reset" property="reset"></html:reset>
this below was the plain html code-->
<!-- <input type="button" name="thesubmit" value="Submit" onClick="everything(this.form)">
<input type="reset" name="reset" value="Reset">
-->
[/HTML]

Awaiting response :)
regards,
ajos
Nov 22 '07 #16

acoder
Expert Mod 15k+
P: 16,027
I've merged this thread with an older thread of yours on the same topic.

If the function everything returns true, the form will submit.
Nov 22 '07 #17

100+
P: 283
I've merged this thread with an older thread of yours on the same topic.

If the function everything returns true, the form will submit.
hey acoder,
I know thats the case and made the changes accordingly.....but still the result is not comming as desired.
ive updated it as--->
Expand|Select|Wrap|Line Numbers
  1. function everything(form) 
  2. {
  3. var errors=0;
  4. if(!isdate(form))
  5. errors++;
  6. if(!isbrief(form))
  7. errors++;
  8. if(!isdigit(form))
  9. errors++;
  10. if(!isperiod(form))
  11. errors++;
  12. if(!isproposed(form))
  13. errors++;
  14. if(!isapprove(form)
  15. errors++;
  16. if(!allblanks(form))
  17. errors++;
  18. if(errors == 0)
  19. return true;
  20. else
  21. {
  22. compose(form);
  23. return false;
  24. }
  25. }
  26.  
  27.  
regards,
ajos
Nov 22 '07 #18

100+
P: 283
hey acoder,
I know thats the case and made the changes accordingly.....but still the result is not comming as desired.
ive updated it as--->
Expand|Select|Wrap|Line Numbers
  1. function everything(form) 
  2. {
  3. var errors=0;
  4. if(!isdate(form))
  5. errors++;
  6. if(!isbrief(form))
  7. errors++;
  8. if(!isdigit(form))
  9. errors++;
  10. if(!isperiod(form))
  11. errors++;
  12. if(!isproposed(form))
  13. errors++;
  14. if(!isapprove(form)
  15. errors++;
  16. if(!allblanks(form))
  17. errors++;
  18. if(errors == 0)
  19. return true;
  20. else
  21. {
  22. compose(form);
  23. return false;
  24. }
  25. }
  26.  
  27.  
regards,
ajos
friends, still no luck :(
Where am i going wrong? can any one help me??
Nov 22 '07 #19

acoder
Expert Mod 15k+
P: 16,027
allblanks checks everything all over again and doesn't return true/false.

Do you see any errors?
Nov 22 '07 #20

100+
P: 283
allblanks checks everything all over again and doesn't return true/false.

Do you see any errors?
ok. Ive removed the all blanks method and declarations....still nothing happens.
Nov 22 '07 #21

acoder
Expert Mod 15k+
P: 16,027
What does [HTML]<html:form action="/ExpenReqAction" name="expenreqForm" type="publicity.ExpenReqForm" method="post" onsubmit="return everything(this);">[/HTML] get converted into on the client-side?
Nov 22 '07 #22

100+
P: 283
What does [HTML]<html:form action="/ExpenReqAction" name="expenreqForm" type="publicity.ExpenReqForm" method="post" onsubmit="return everything(this);">[/HTML] get converted into on the client-side?
That would be--->
[HTML]
<form name="expenreqForm" method="post" action="/struts-test/ExpenReqAction.do" onsubmit="return everything(this);">
[/HTML]
Nov 22 '07 #23

acoder
Expert Mod 15k+
P: 16,027
There's too much duplication here.

Make one function similar to your current compose function, but add in a return true (if no errors) and false if there are errors.
Nov 22 '07 #24

100+
P: 283
There's too much duplication here.

Make one function similar to your current compose function, but add in a return true (if no errors) and false if there are errors.
Im not sure what you meant by duplication here.
I did as you said, about the similar compose function. Im not a javascript person, yet i tried. This is how it goes. Please correct me.
Expand|Select|Wrap|Line Numbers
  1. function composed(form)
  2. {
  3.  
  4. var errors=0;
  5. if(!isdate(form))
  6. errors++;
  7. return false;
  8. else
  9. {
  10. return true;
  11. }
  12. if(!isbrief(form))
  13. errors++;
  14. return false;
  15. else
  16. {
  17. return true;
  18. }
  19.  
  20. if(!isperiod(form))
  21. errors++;
  22. return false;
  23. else
  24. {
  25. return true;
  26. }
  27.  
  28. if(!isproposed(form))
  29. errors++;
  30. return false;
  31. else
  32. {
  33. return true;
  34. }
  35.  
  36. if(!isapproved(form))
  37. errors++;
  38. return false;
  39. else
  40. {
  41. return true;
  42. }
  43.  if(!isdigit(form))
  44.  errors++;
  45.  return false;
  46.  else
  47.  {
  48.  return true;
  49.  }
  50.  
  51. }
  52.  
Eager to hear from you. :)
Nov 22 '07 #25

acoder
Expert Mod 15k+
P: 16,027
See Form Validation to have an idea of a validation function which checks all the fields.

Try something like:
Expand|Select|Wrap|Line Numbers
  1. function everything(form) {
  2.  var errors = "";
  3.  errors += isdate(form);
  4.  errors += isbrief(form);
  5.  errors += isperiod(form);
  6.  errors += isproposed(form);
  7.  errors += isapproved(form);
  8.  errors += isdigit(form);
  9.  if (errors != "") {
  10.   alert("You have the following errors: "+errors);
  11.   return false;
  12.  }
  13.  return true;
  14. }
where each is*** function returns a string (empty if there's no error).
Nov 22 '07 #26

100+
P: 283
See Form Validation to have an idea of a validation function which checks all the fields.

Try something like:
Expand|Select|Wrap|Line Numbers
  1. function everything(form) {
  2.  var errors = "";
  3.  errors += isdate(form);
  4.  errors += isbrief(form);
  5.  errors += isperiod(form);
  6.  errors += isproposed(form);
  7.  errors += isapproved(form);
  8.  errors += isdigit(form);
  9.  if (errors != "") {
  10.   alert("You have the following errors: "+errors);
  11.   return false;
  12.  }
  13.  return true;
  14. }
where each is*** function returns a string (empty if there's no error).
Ive done something like this but its still not working, i did this according to the link you had sent me.

Expand|Select|Wrap|Line Numbers
  1. function setdate1(form) {
  2. var now = new Date();
  3. var date = now.getDate();
  4. var month = now.getMonth();
  5. var year = now.getFullYear();
  6. // old var year = now.getYear();
  7. newyear = year
  8. newmonth = month+1;
  9. var date1 = date+"/"+newmonth+"/"+newyear;
  10. form.date.value=date1;
  11. form.approved_by.value="Neeta Asnani";
  12. }
  13.  
  14. function everything(form)
  15. {
  16. var errors= "";
  17. errors += isdate(form);
  18. errors += isbrief(form);
  19. errors += isdigit(form);
  20. errors += isperiod(form);
  21. errors += isproposed(form);
  22. errors += isapprove(form);
  23. if(errors != "")
  24. {
  25. alert("You have the following errors" +errors);
  26. return false;
  27. }
  28. return true;
  29. }
  30.  
  31. function isdate(form)
  32. {
  33. var errors= "";
  34. if(form.date.value= "")
  35. {
  36. errors= "You didnt enter a proper date.\n";
  37. }
  38. if(form.date.value.length>10)
  39. {
  40. errors= "The date must not be greater than 10 chars.\n";
  41. }
  42. return errors;
  43. }
  44.  
  45. function isbrief(form)
  46. {
  47. var errors= "";
  48. if(form.brief1.value= "")
  49. {
  50. errors= "Please enter Brief1 value.\n";
  51. }
  52. return errors;
  53. }
  54.  
  55. function isdigit(form)
  56. {
  57. var errors= "";
  58. if(form.amount.value= "")
  59. {
  60. errors= "Please enter amount value.\n";
  61. }
  62. return errors;
  63. }
  64.  
  65. function isperiod(form)
  66. {
  67. var errors= "";
  68. if(form.period.value= "")
  69. {
  70. errors="Please enter period value.\n";
  71. }
  72. return errors;
  73. }
  74.  
  75. function isproposed(form)
  76. {
  77. var errors= "";
  78. if(form.proposed_by.value= "")
  79. {
  80. errors= "Please enter proposed by value.\n";
  81. }
  82. return errors;
  83. }
  84.  
  85. function isapprove(form)
  86. {
  87. var errors= "";
  88. if(form.approved_by.value= "")
  89. {
  90. errors= "Please enter approved by value.\n";
  91. }
  92. return errors;
  93. }
  94.  
Ive lost faith now. Please help me.
Nov 23 '07 #27

acoder
Expert Mod 15k+
P: 16,027
Ive done something like this but its still not working
When you say it's not working, what do you mean? What happens? Do you get any errors?
Nov 23 '07 #28

100+
P: 283
When you say it's not working, what do you mean? What happens? Do you get any errors?
Sorry im just out of words and thoughts, What i mean by not working was the i get a error, at line 85 which is this--->

Expand|Select|Wrap|Line Numbers
  1. String s18="";
  2.             Double double1 = new Double(s18);
  3.  
exception-->java.lang.NumberFormatException: empty String
but i dont think the validation fails due to this. Coz the validation is done at client side.
Nov 23 '07 #29

acoder
Expert Mod 15k+
P: 16,027
Do you not think that might be affecting the client-side code? I think you should get rid of that error, so that you remove all other possibilities.
Nov 23 '07 #30

100+
P: 283
Do you not think that might be affecting the client-side code? I think you should get rid of that error, so that you remove all other possibilities.
hey acoder thanks for the support so far, i appreciate it. I'll get back to you after some RnD on the matter.
regards,
ajos
Nov 23 '07 #31

acoder
Expert Mod 15k+
P: 16,027
No problem.

Just post back when you've solved that problem - hopefully the validation problem might not be too far off from solving either.
Nov 23 '07 #32

Post your reply

Sign in to post your reply or Sign up for a free account.