MrFahad
asked on
2 functions in same onsubmit
hello, i have a form in which i want to have 2 function run same time one for form validation and other for form submitting confirmation, so what did i do wrong
<td width="900" id="page">
<h2>Add Property</h2>
<script language="JavaScript" type="text/javascript" src="javascript/wysiwyg.js"></script>
<script language="javascript" type="text/javascript" src="javascript/form_confirmation.js"></script>
<script language="javascript" type="text/javascript" src="javascript/validation.js"></script>
<div id="wrapper">
<form name="form" enctype="multipart/form-data" id="form" action="create_property.php" onSubmit="return validate(this)";"return test()" method="post" >
<fieldset>
<legend><b>Property Name</b></legend>
<label for="PropertyName"><em>Please insert a unique property name:</em></label>
<input name="PropertyName" type="text" id="PropertyName" />
</fieldset>
<br />
<fieldset>
<legend><b>Property Type</b></legend>
<em> Please enter the type of the property that you are adding:
</em> <select name="PropertyType">
<option value="1">Apartment</option>
<option value="2">Villa</option>
</select>
</fieldset>
<br />
<fieldset>
<legend><b>Property Photo:</b></legend>
<input type="file" name="photo" id="photo">
</fieldset>
<br />
<fieldset>
<legend><b>Property Address</b></legend>
<label for="PropertyAddress"><em>Please enter the address of the property</em>:</label>
<input name="PropertyAddress" type="text" id="PropertyAddress"/>
</fieldset>
<br/>
<fieldset>
<legend><b>Area Of Property</b></legend>
<label for="Area"><em>Please add the area of the property</em>:</label>
<input name="Area" type="text" value="" id="Area" /> <p>*only numbers allowed, use meter sequire</p>
</fieldset>
<br />
<fieldset>
<legend><b>Listing Price:</b></legend>
<em>Please enter the price of the property:</em>
<input name="listedPrice" type="text" value="" id="listedPrice"/>
</fieldset>
<br />
<fieldset>
<legend><b>Number Of Bed Rooms:</b></legend>
Please enter the number of bedrooms of the property:
<select name="No_bedroom">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
</select>
</fieldset>
<br />
<fieldset>
<legend><b>Listing Date:</b></legend>
<select name="lmonth" >
<option value='01'>January</option>
<option value='02'>February</option>
<option value='03'>March</option>
<option value='04'>April</option>
<option value='05'>May</option>
<option value='06'>June</option>
<option value='07'>July</option>
<option value='08'>August</option>
<option value='09'>September</option>
<option value='10'>October</option>
<option value='11'>November</option>
<option value='12'>December</option>
</select>
Month
<select name="ldate" >
<option value='01'>01</option>
<option value='02'>02</option>
<option value='03'>03</option>
<option value='04'>04</option>
<option value='05'>05</option>
<option value='06'>06</option>
<option value='07'>07</option>
<option value='08'>08</option>
<option value='09'>09</option>
<option value='10'>10</option>
<option value='11'>11</option>
<option value='12'>12</option>
<option value='13'>13</option>
<option value='14'>14</option>
<option value='15'>15</option>
<option value='16'>16</option>
<option value='17'>17</option>
<option value='18'>18</option>
<option value='19'>19</option>
<option value='20'>20</option>
<option value='21'>21</option>
<option value='22'>22</option>
<option value='23'>23</option>
<option value='24'>24</option>
<option value='25'>25</option>
<option value='26'>26</option>
<option value='27'>27</option>
<option value='28'>28</option>
<option value='29'>29</option>
<option value='30'>30</option>
<option value='31'>31</option>
</select>
Date
<input name="lyear" type="text" size="4" id="lyear"/>
Year(yyyy)
</fieldset>
<br/>
<fieldset>
<legend><b>Date build:</b></legend>
<select name="month">
<option value='01'>January</option>
<option value='02'>February</option>
<option value='03'>March</option>
<option value='04'>April</option>
<option value='05'>May</option>
<option value='06'>June</option>
<option value='07'>July</option>
<option value='08'>August</option>
<option value='09'>September</option>
<option value='10'>October</option>
<option value='11'>November</option>
<option value='12'>December</option>
</select>
Month
<select name="date" >
<option value='01'>01</option>
<option value='02'>02</option>
<option value='03'>03</option>
<option value='04'>04</option>
<option value='05'>05</option>
<option value='06'>06</option>
<option value='07'>07</option>
<option value='08'>08</option>
<option value='09'>09</option>
<option value='10'>10</option>
<option value='11'>11</option>
<option value='12'>12</option>
<option value='13'>13</option>
<option value='14'>14</option>
<option value='15'>15</option>
<option value='16'>16</option>
<option value='17'>17</option>
<option value='18'>18</option>
<option value='19'>19</option>
<option value='20'>20</option>
<option value='21'>21</option>
<option value='22'>22</option>
<option value='23'>23</option>
<option value='24'>24</option>
<option value='25'>25</option>
<option value='26'>26</option>
<option value='27'>27</option>
<option value='28'>28</option>
<option value='29'>29</option>
<option value='30'>30</option>
<option value='31'>31</option>
</select>
Date
<input name="year" type="text" size="4" id="year" />
Year(yyyy)
</fieldset>
<br/>
<fieldset>
<legend><b>Description:</b></legend>
<textarea name="description" value="" id="description"></textarea> <script language="javascript">
generate_wysiwyg('description');
</script>
<input type="submit" value="submit" />
</fieldset>
</form>
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Try
onsubmit="validate(this);t est();"
onsubmit="validate(this);t
Are you sure your validate function returns true?
Another way would be to combine both functions into a single one.
Another way would be to combine both functions into a single one.
ASKER
here is the other function code
// form validation function //
function validate(form) {
var PropertyName = form.PropertyName.value;
var PropertyType = form.PropertyType.value;
var photo = form.photo.value;
var PropertyAddress = form.PropertyAddress.value;
var Area = form.Area.value;
var listedPrice = form.listedPrice.value;
var lyear = form.lyear.value;
var description = form.description.value;
var photoRegex = /^.+\.(jpe?g|bmp|png|gif)$/i;
var addressRegex = /^[\da-z ,]*$/ig;
var PropertyNameRegex = /^[\da-z ,]*$/ig;
var descriptionRegex = /^[a-zA-Z]+(([\'\,\.\- ][a-zA-Z ])?[a-zA-Z]*)*$/;
var AreaRegex = /^[0-9]*$/;
var listedPriceRegex = /^[0-9]*$/;
var lyearRegex = /^[0-9]*$/;
var yearRegex = /^[0-9]*$/;
if(PropertyName == "") {
inlineMsg('PropertyName','<strong>Error</strong><br />You must enter the name of the property.',2);
return false;
}
if(!PropertyName.match(PropertyNameRegex)) {
inlineMsg('PropertyName','<strong>Error</strong><br />You have entered an invalid property name.',2);
return false;
}
if(PropertyType == "") {
inlineMsg('PropertyType','<strong>Error</strong><br />You must enter the type of the property.',2);
return false;
}
if(photo == "") {
inlineMsg('photo','<strong>Error</strong><br />You must enter the photo of the property.',2);
return false;
}
if(!photo.match(photoRegex)) {
inlineMsg('photo','<strong>Error</strong><br />You have entered an invalid property photo format. Please use .jpg .jpge .png or .gif format',2);
return false;
}
if(PropertyAddress == "") {
inlineMsg('PropertyAddress','<strong>Error</strong><br />You Have entered an invalid type of the property.',2);
return false;
}
if(!PropertyAddress.match(addressRegex)) {
inlineMsg('PropertyAddress','<strong>Error</strong><br />You have entered an invalid property address.',2);
return false;
}
if(Area == "") {
inlineMsg('Area','<strong>Error</strong><br />You must enter the area of the property.',2);
return false;
}
if(!Area.match(AreaRegex)) {
inlineMsg('Area','<strong>Error</strong><br />You have entered an invalid area.',2);
return false;
}
if(listedPrice == "") {
inlineMsg('listedPrice','<strong>Error</strong><br />You must enter the price of the property.',2);
return false;
}
if(!listedPrice.match(listedPriceRegex)) {
inlineMsg('listedPrice','<strong>Error</strong><br />You have entered an invalid price.',2);
return false;
}
if(lyear == "") {
inlineMsg('lyear','<strong>Error</strong><br />You must enter the listing year of the property.',2);
return false;
}
if(!lyear.match(lyearRegex)) {
inlineMsg('lyear','<strong>Error</strong><br />You have entered an invalid year.',2);
return false;
}
if(description == "") {
inlineMsg('description','You must enter a discription.');
return false;
}
if(description.match(descriptionRegex)) {
inlineMsg('description','You have entered an invalid message.');
return false;
}
}
// START OF MESSAGE SCRIPT //
var MSGTIMER = 20;
var MSGSPEED = 5;
var MSGOFFSET = 3;
var MSGHIDE = 3;
// build out the divs, set attributes and call the fade function //
function inlineMsg(target,string,autohide) {
var msg;
var msgcontent;
if(!document.getElementById('msg')) {
msg = document.createElement('div');
msg.id = 'msg';
msgcontent = document.createElement('div');
msgcontent.id = 'msgcontent';
document.body.appendChild(msg);
msg.appendChild(msgcontent);
msg.style.filter = 'alpha(opacity=0)';
msg.style.opacity = 0;
msg.alpha = 0;
} else {
msg = document.getElementById('msg');
msgcontent = document.getElementById('msgcontent');
}
msgcontent.innerHTML = string;
msg.style.display = 'block';
var msgheight = msg.offsetHeight;
var targetdiv = document.getElementById(target);
targetdiv.focus();
var targetheight = targetdiv.offsetHeight;
var targetwidth = targetdiv.offsetWidth;
var topposition = topPosition(targetdiv) - ((msgheight - targetheight) / 2);
var leftposition = leftPosition(targetdiv) + targetwidth + MSGOFFSET;
msg.style.top = topposition + 'px';
msg.style.left = leftposition + 'px';
clearInterval(msg.timer);
msg.timer = setInterval("fadeMsg(1)", MSGTIMER);
if(!autohide) {
autohide = MSGHIDE;
}
window.setTimeout("hideMsg()", (autohide * 1000));
}
// hide the form alert //
function hideMsg(msg) {
var msg = document.getElementById('msg');
if(!msg.timer) {
msg.timer = setInterval("fadeMsg(0)", MSGTIMER);
}
}
// face the message box //
function fadeMsg(flag) {
if(flag == null) {
flag = 1;
}
var msg = document.getElementById('msg');
var value;
if(flag == 1) {
value = msg.alpha + MSGSPEED;
} else {
value = msg.alpha - MSGSPEED;
}
msg.alpha = value;
msg.style.opacity = (value / 100);
msg.style.filter = 'alpha(opacity=' + value + ')';
if(value >= 99) {
clearInterval(msg.timer);
msg.timer = null;
} else if(value <= 1) {
msg.style.display = "none";
clearInterval(msg.timer);
}
}
// calculate the position of the element in relation to the left of the browser //
function leftPosition(target) {
var left = 0;
if(target.offsetParent) {
while(1) {
left += target.offsetLeft;
if(!target.offsetParent) {
break;
}
target = target.offsetParent;
}
} else if(target.x) {
left += target.x;
}
return left;
}
// calculate the position of the element in relation to the top of the browser window //
function topPosition(target) {
var top = 0;
if(target.offsetParent) {
while(1) {
top += target.offsetTop;
if(!target.offsetParent) {
break;
}
target = target.offsetParent;
}
} else if(target.y) {
top += target.y;
}
return top;
}
// preload the arrow //
if(document.images) {
arrow = new Image(70,80);
arrow.src = "images/msg_arrow.gif";
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
So, you don't have "return true;" after all checks in validate function.
ASKER
thanks it worked
ASKER
Open in new window