473,386 Members | 1,830 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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

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
1 2828
omerbutt
638 512MB
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

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

Similar topics

3
by: NotGiven | last post by:
I have a web form with several fields. If I copy & paste from a RTF document into a field, the javascript validation and field length are bypassed and cause the form to fail. Any ideas?
4
by: John Fereira | last post by:
So, one of the limitations of multipart-form handling is that when an <input type="file" ..> tag is used it will bring up a window which allows a user to select a file for upload but won't allow...
0
by: Julieb215 | last post by:
I have an asp.net page that needs to spawn off a popup - printer friendly page. To do that when the user clicks the printer button I fire off the following code: Dim jj As String jj = "<script...
4
by: DMG | last post by:
I have <identity impersonate = "true" /& <authentication mode="Windows"/in the web.config. This is a 2.0 site. My Goal: I want to simply have the user browse to a file on a mapped drive and get...
1
by: karen987 | last post by:
I have a comment form, on a news website, ASP page, which users fill in and it adds comments to a news article. The reader clicks on a headline and the comments open up in a new window. It already...
1
by: ll | last post by:
Hi, I am working with a page that has both cfform elements and 'plain html' form elements. In particular, I am needing to validate my textarea form field and my email text field. On one of my...
1
by: runway27 | last post by:
i have 3 pages page1.php page2.php and page3.php in page1.php user fills a registration form in page2.php the user can review what they have entered and make any changes and page3.php...
8
by: SJ Carter | last post by:
Hello guys, I have the following piece of code: function validate() { var f = document.form1; if (f.name.value == "" || f.name.value == '' || f.name.value.length == 0) { alert('Please enter...
1
by: jerrydigital | last post by:
Hello, I have a form that i use ASP to process the form to my access database. It works well but I'm struggling to get the javascript validation to work. I have posted a small version of my form...
12
by: btreddy | last post by:
Hii Experts, im facing a problem with the javascript validation.i've a gridview in my web form and added a footer tempalte and placed textboxes in tht tempalte ,just to add a new row to the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.