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

Javascript validation not working with form of multipart/form-data

P: 1
Hi guys,

Been stuck for a few days with this scenario.
Any help?
The alert box appears on an error.
But the submitting won't stop.
The details are submitted and the form is processed.
Any help is greatly appreciated...

Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. <script type="text/javascript" src="email_helper/jscripts/tiny_mce/tiny_mce.js"></script>
  4. <script type="text/javascript">
  5.     tinyMCE.init({
  6.         // General options
  7.         mode : "textareas",
  8.         theme : "simple"
  9.     });
  10. </script>
  11. <script language="javascript">
  12.  
  13. function MM_openBrWindow(theURL,winName,features) {
  14.     window.open(theURL,winName,features);
  15. }
  16. function err_check(){
  17.     var email = document.getElementById('to_email').value;
  18.     if(email.length==0){
  19.         alert('Please Enter Email Address');
  20.         return;
  21.     }
  22.     var AtPos = email.indexOf("@")
  23.     var StopPos = email.lastIndexOf(".")
  24.     if (AtPos == -1 || StopPos == -1) {
  25.         alert("Please Enter Valid Email Address");
  26.         document.getElementById('email').focus();
  27.         return;
  28.     }
  29.     email = document.getElementById('cc_email').value;
  30.     if(email.length != 0){
  31.         var AtPos = email.indexOf("@")
  32.         var StopPos = email.lastIndexOf(".")
  33.         if (AtPos == -1 || StopPos == -1) {
  34.             alert("Please Enter Valid Email Address");
  35.             document.getElementById('email').focus();
  36.             return false;
  37.         }
  38.     }
  39.     var answer = confirm ("Send E-Mail?");
  40.     if (!answer){
  41.         return false;
  42.     }
  43. }
  44. </script>
  45. <!-- /TinyMCE -->
  46.  
  47.  
  48. <style type="text/css">
  49. body, table, td, th{
  50.     background-color:#CCCCCC;
  51.     font-family: Arial;
  52.     font-size:14px;
  53. }
  54. .que{
  55.     font-weight:bold;
  56. }
  57. </style>
  58. </head>
  59. <body>
  60. <form method="post" enctype="multipart/form-data">
  61. <?php
  62. include 'library/database.php';
  63. include 'library/opendb.php';
  64. $query = mysql_query("SELECT email,contact,mobile FROM users WHERE user_id='$uid'") or die(mysql_error());
  65. $row = mysql_fetch_row($query);
  66. $from_email = $row[0];
  67. $from_person = $row[1];
  68. $from_mobile = $row[2];
  69. $query = mysql_query("SELECT customer_id FROM campaign_summary WHERE camp_id='$camp_id'") or die(mysql_error());
  70. $row = mysql_fetch_row($query);
  71. $cusid = $row[0];
  72. $query = mysql_query("SELECT email FROM client_info WHERE comp_id='$cusid'") or die(mysql_error());
  73. $row = mysql_fetch_row($query);
  74. $toer = $row[0];
  75. include 'library/closedb.php';
  76. ?>
  77. <table width="100%" border="0">
  78. <tr><td rowspan="4"><input type="submit" name="send_email" id="send_email" style="height:50px; width:100px;" value="SEND" onClick="return err_check();" /></td><td><span class="que">From : </span></td><td colspan="3"><?php echo $from_email; ?><input type="hidden" name="from_mail" id="from_mail" /><input type="hidden" name="camp_id" id="camp_id" value="<?php echo $camp_id;?>"/></td></tr>
  79. <tr><td><span class="que">To : </span></td><td colspan="3"><input name="to_email" id="to_email" style="width:250px;" value="<?php echo $toer;?>"/></td></tr>
  80. <tr><td><span class="que">CC : </span></td><td colspan="3"><input name="cc_email" id="cc_email" style="width:250px;"/></td></tr>
  81. <tr><td><span class="que">Subject : </span></td><td colspan="3"><input style="width:300px;" name="subject" id="subject" /></td></tr>
  82. <tr><td rowspan="1" colspan="2">&nbsp;</td><td><input type="checkbox" name="ori_pdf" id="ori_pdf" checked /> PDF Quotation</td><td>&nbsp;</td><td>&nbsp;</td></tr><tr><td colspan="2"><span class="que">Credit Application</span></td><td><input type="checkbox" name="corporate" id="corporate"/>Corporate</td><td><input type="checkbox" name="individual" id="individual" />Individual</td><td><input type="checkbox" name="cash" id="cash" />Cash Account</td>
  83. </tr>
  84. <tr>
  85. <td colspan="2" rowspan="3"></td><td><input type="checkbox" name="tabloid" id="tabloid" />Tabloid Example</td>
  86. <td><input type="checkbox" name="broadsheet" id="broadsheet" />Broadsheet Example</td></tr>
  87. <tr><td><input type="checkbox" name="colmt" id="colmt" />Column Sizes Tabloid</td>
  88.  
  89. <td><input type="checkbox" name="colmb" id="colmb" />Column Sizes Broadsheet</td></tr>
  90. <tr><td><input type="checkbox" name="maps" id="maps" />Maps / Distribution</td><td colspan="2" align="right">External Attachments&nbsp;&nbsp;<input id="upload_file" name="upload_file" type="file"/> </td></tr>
  91.  
  92. <tr><td colspan="2"><span class="que">Message :</span></td><td colspan="3">
  93.     <textarea id="elm1" name="elm1" rows="15" cols="80" style="width: 100%">
  94.     <?php
  95.      echo "<br><br><br>" . $from_person . "<br>" . $from_mobile; 
  96.       ?>
  97.     </textarea>
  98. </td></tr>
  99. </table>
  100. </form>
  101. </body>
  102. </html>
  103.  
Nov 29 '11 #1
Share this Question
Share on Google+
1 Reply


omerbutt
100+
P: 638
Hi elabuwa,
always remember one thing that when you use
Expand|Select|Wrap|Line Numbers
  1. <input type="submit">
never use onclick method to call the validation,or any other function ,use onsubmit attribute of the form instead.
Expand|Select|Wrap|Line Numbers
  1. <form name="myForm" onsubmit="return validation()">
you always use return before the fnction name when using the onsubmit property but not the onclick property of the submit or button type input as you have done here in your code,
Expand|Select|Wrap|Line Numbers
  1.  <tr><td rowspan="4"><input type="submit" name="send_email" id="send_email" style="height:50px; width:100px;" value="SEND" onClick="return err_check();" /></td>
But if you do want to use onclick then you need to change to
Expand|Select|Wrap|Line Numbers
  1. <input type="button" onclick="validation();">
, so in your code change the type from submit to button on line 78 , and you see it start working fine.
regards,
Omer Aslam
Dec 2 '11 #2

Post your reply

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