My form is unable to validate. When i click the continue button it will straight away proceed to the next page. The scenario is when user click the Continue button without filling the details, it will direct user to fill in the form based on the validation. There’s a checkbox which enable to copy the top fields to the recipient fields. I couldn’t spot the error.
checkout.php
<form name="shippingForm" method="post" id="shippingForm"
onsubmit="return chkForm(this)">
<select name="inputtitle" class="inputtitle" id="inputtitle">
<option value="Mr"
<?php if($memberInfo['title'] == 'Mr'){ echo 'selected'; } ?>>Mr.</option>
<option value="Mrs"
<?php if($memberInfo['title'] == 'Mrs'){ echo 'selected'; } ?>>Mrs.</option>
<option value="Ms"
<?php if($memberInfo['title'] == 'Ms'){ echo 'selected'; } ?>>Ms.</option>
</select> <br>
<p>First Name</p>
<input id="SfirstName" class="fname" name="recipientFirstName"
type="text" placeholder="First Name "
value="<?php echo isset($memberInfo['firstName']) ? $memberInfo['firstName'] : '' ?>"><br>
<p>Last Name</p>
<input id="SlastName" class="lname" name="lname" type="text"
placeholder="Last Name "
value="<?php echo isset($memberInfo['lastName']) ? $memberInfo['lastName'] : '' ?>">
<br>
<div class="checkitem">
<div class="labelitem-left">
<p>Postal*</p>
</div>
<div class="labelitem-right">
<p>Unit Number*</p>
</div>
</div>
<div class="inputitem">
<div class="inputitem-left">
<input id="postal" name="postal" type="text" class="input-left"
value="<?php echo isset($memberInfo['details'][0]['billingPostal']) ? $memberInfo['details'][0]['billingPostal'] : '' ?>">
</div>
<div class="inputitem-right">
<input id="unitNum" name="unitNum" type="text"
class="input-right"
value="<?php echo isset($memberInfo['details'][0]['billingAddr1']) ? $memberInfo['details'][0]['billingAddr1'] : '' ?>">
</div>
</div>
<p>Address</p>
<input id="addr" class="address" name="addr" type="text"
placeholder="Address"
value="<?php echo isset($memberInfo['details'][0]['billingAddr2']) ? $memberInfo['details'][0]['billingAddr2'] : '' ?>"><br>
<div class="checkitem">
<div class="labelitem-left">
<p>Mobile Number*</p>
</div>
<div class="labelitem-right">
<p>Home Number</p>
</div>
</div>
<div class="inputitem">
<div class="inputitem-left">
<input id="mobileNum" name="mobileNum" " type="text"
class="input-left"
onkeypress="return event.charCode >= 48 && event.charCode <= 57 || event.charCode == 0"
placeholder="Mobile Number "
value="<?php echo isset($memberInfo['details'][0]['billingContactMobile']) ? $memberInfo['details'][0]['billingContactMobile'] : '' ?>">
</div>
<div class="inputitem-right">
<input id="homeNum" name="homeNum" type="text"
onkeypress="return event.charCode >= 48 && event.charCode <= 57 || event.charCode == 0"
placeholder="Home Number " class="input-right"
value="<?php echo isset($memberInfo['details'][0]['billingContactHome']) ? $memberInfo['details'][0]['billingContactHome'] : '' ?>">
</div>
</div>
<div class="checkitem">
<div class="labelitem-left">
<p>Acquirement Method</p>
</div>
<div class="labelitem-right">
<p>Delivery Date</p>
</div>
</div>
<div class="inputitem">
<div class="inputitem-left">
<select name="method" class="input-left" id="method">
<option value="false">Delivery</option>
<option value="true">Pickup at outlet</option>
</select>
</div>
<div class="inputitem-right">
<input id="dDate" name="dDate" type="date" class="input-right"
value="" value="<?php echo $user_profile["dDate"]; ?>">
</div>
</div>
<br>Delivery Time* <br> <br> <input type="radio" class="radiodtime"
name="dtime" value="anytime">Anytime between <select name="dtime"
class="dtime" id="dtime">
<option value="12pm-3pm"
<?php if($user_profile['dtime'] == '12pm-3pm'){ echo 'selected'; } ?>>12
pm - 3 pm</option>
<option value="3pm-5pm"
<?php if($user_profile['dtime'] == '3pm-5pm'){ echo 'selected'; } ?>>3
pm - 5 pm</option>
<option value="5pm-7pm"
<?php if($user_profile['dtime'] == '5pm-7pm'){ echo 'selected'; } ?>>5
pm - 7 pm</option>
</select> <br> <br> <input type="radio" name="dtime"
value="anytime">Specifically at <select name="dtime" class="dtime"
id="dtime">
<option value="1"
<?php if($user_profile['dtime'] == '1'){ echo 'selected'; } ?>> 1</option>
<option value="2"
<?php if($user_profile['dtime'] == '2'){ echo 'selected'; } ?>> 2</option>
<option value="3"
<?php if($user_profile['dtime'] == '3'){ echo 'selected'; } ?>> 3</option>
<option value="4"
<?php if($user_profile['dtime'] == '4'){ echo 'selected'; } ?>> 4</option>
<option value="5"
<?php if($user_profile['dtime'] == '5'){ echo 'selected'; } ?>> 5</option>
<option value="6"
<?php if($user_profile['dtime'] == '6'){ echo 'selected'; } ?>> 6</option>
<option value="7"
<?php if($user_profile['dtime'] == '7'){ echo 'selected'; } ?>> 7</option>
<option value="8"
<?php if($user_profile['dtime'] == '8'){ echo 'selected'; } ?>> 8</option>
</select> PM <br>
<div
style="margin-left: 35%; margin-bottom: 10px; font-size: 15px;">+
/ - 30 minutes</div>
<div class="checkoutbox"
style="padding-top: 10px; padding-bottom: 10px;">
<input type="checkbox" name="agree" id="agree"
onclick="FillCheckout(this)"> Tick here, if
Recipient's address is the same as Sender's address.
</div>
<div class="checkitem">
<div class="labelitem-left">
<p>Recipient Title</p>
</div>
</div>
<div class="inputitem">
<select name="Rtitle" class="inputtitle" id="Rtitle">
<option value="Mr"
<?php if($memberInfo['title'] == 'Mr'){ echo 'selected'; } ?>>Mr.</option>
<option value="Mrs" zz
<?php if($memberInfo['title'] == 'Mrs'){ echo 'selected'; } ?>>Mrs.</option>
<option value="Ms"
<?php if($memberInfo['title'] == 'Ms'){ echo 'selected'; } ?>>Ms.</option>
</select> <br>
<p>Recipient's First Name</p>
<input id="RfirstName" class="fname" name="recipientFirstName"
type="text" placeholder="First Name "
value="<?php echo isset($memberInfo['firstName']) ? $memberInfo['firstName'] : '' ?>"><br>
<p>Recipient's Last Name</p>
<input id="RlastName" class="lname" name="recipientLastName"
type="text" placeholder="Last Name "
value="<?php echo isset($memberInfo['lastName']) ? $memberInfo['lastName'] : '' ?>">
</div>
<div class="checkitem">
<div class="labelitem-left">
<p style="text-align: initial;">Recipient's Mobile Number*</p>
</div>
<div class="labelitem-right">
<p>Recipient's Postal*</p>
</div>
</div>
<div class="inputitem">
<div class="inputitem-left">
<input id="RmobileNum" name="RmobileNum" type="text"
class="input-left"
onkeypress="return event.charCode >= 48 && event.charCode <= 57 || event.charCode == 0"
placeholder="+65 "
value="<?php echo isset($memberInfo['details'][0]['billingContactMobile']) ? $memberInfo['details'][0]['billingContactMobile'] : '' ?>">
</div>
<div class="inputitem-right">
<input id="Rpostal" name="Rpostal" type="text"
class="input-right" value=""
onkeypress="return event.charCode >= 48 && event.charCode <= 57 || event.charCode == 0"
value="<?php echo isset($memberInfo['details'][0]['billingPostal']) ? $memberInfo['details'][0]['billingPostal'] : '' ?>">
</div>
</div>
<div class="checkitem">
<div class="labelitem-left">
<p style="text-align: initial;">Recipient Unit Number*</p>
</div>
<div class="labelitem-right">
<p>Recipient Address*</p>
</div>
</div>
<div class="inputitem">
<div class="inputitem-left">
<input id="RunitNum" name="RunitNum" type="text"
class="input-left"
value="<?php echo isset($memberInfo['details'][0]['billingPostal']) ? $memberInfo['details'][0]['billingPostal'] : '' ?>">
</div>
<div class="inputitem-right">
<input id="Raddr" name="Raddr" type="text" class="input-right"
value="<?php echo isset($memberInfo['details'][0]['billingAddr2']) ? $memberInfo['details'][0]['billingAddr2'] : '' ?>">
</div>
</div>
<div style="float: right; padding-top: 40px;" class="g-recaptcha"
data-sitekey="6LetxQsTAAAAAD4xOk_Yd2B1s1kbK7wLP4OnatXg" required></div>
<button class="checkout" type="submit" value="Continue"
style="margin-left: 100%; margin-top: 5%; float: right;"
id="continue" name="continue"
onclick="return chkForm()">Continue
</form>
js
<script type="text/javascript">
function chkForm(form) {
if(form.inputtitle.value == "" && form.SfirstName.value == "" && form.SlastName.value == "" && form.postal.value == "" && form.unitNum.value == "" && form.addr.value == "" && form.mobileNum.value == "") {
alert("Please fill in the required fields: \n\u26AC Name \n\u26AC Email \n\u26AC Subject \n\u26AC Message");
form.inputtitle.focus();
return false;
}
if(form.SfirstName.value == "") {
alert("Error: First Name cannot be blank!");
form.SfirstName.focus();
return false;
}
if(form.SlastName.value == "") {
alert("Error: First Name cannot be blank!");
form.SlastName.focus();
return false;
}
if(form.postal.value == "") {
alert("Error: Postal Code cannot be blank!");
form.postal.focus();
return false;
}
if(form.unitNum.value == "") {
alert("Error: Unit Number cannot be blank!");
form.unitNum.focus();
return false;
}
if(form.addr.value == "") {
alert("Error: Address cannot be blank!");
form.addr.focus();
return false;
}
if(form.mobileNum.value == "") {
alert("Error: Mobile Number cannot be blank!");
form.mobileNum.focus();
return false;
}
}
</script>
<script type="text/javascript">
function FillCheckout(form)
{
var inputtitle = document.getElementById('inputtitle');
var fname = document.getElementById('SfirstName');
var lname = document.getElementById('SlastName');
var postal = document.getElementById('postal');
var unitNum = document.getElementById('unitNum');
var addr = document.getElementById('addr');
var mobileNum = document.getElementById('mobileNum');
var recipientTitle = document.getElementById('Rtitle');
var recipientFirstName = document.getElementById('RfirstName');
var recipientLastName = document.getElementById('RlastName');
var RmobileNum = document.getElementById('RmobileNum');
var Rpostal = document.getElementById('Rpostal');
var RunitNum = document.getElementById('RunitNum');
var Raddr = document.getElementById('Raddr');
Rtitle.value = inputtitle.value;
RfirstName.value = SfirstName.value;
RlastName.value = SlastName.value;
RmobileNum.value = mobileNum.value;
Rpostal.value = postal.value;
RunitNum.value = unitNum.value;
Raddr.value = addr.value;
}
</script>