Variables don't work - javascript

I need some help with JavaScript. I want to have an "a" link with changeble text. But there is a problem with variables, they don't as they must. There is only ("Successfully check = false") statement in console, never ("Successfully check = true").
There is a code:
changeText.js
function check1() {
document.getElementById("ck").innerHTML = "Включить переливание фона
кликабельно";
return false;
}
function check2() {
document.getElementById("ck").innerHTML = "Отключить переливание фона
кликабельно";
return false;
}
function changeText() {
var check = true;
if (check = true) {
check1();
check == false;
console.log("Successfully check = false");
}
else {
check2();
check == true;
console.log("Successfully check = true");
}
}
index.html
<!DOCTYPE html>
<html lang="ru" dir="ltr">
<head>
<meta charset="utf-8">
<title>Пианинка</title>
</head>
<body>
Отключить переливание фона (кликабельно)
<script src="changeText.js"></script>
</body>
</html>

= is the same as saying SET THIS TO THIS = does not mean EQUAL TO. == and === do, but not =.
So change your code to this:
function check1() {
document.getElementById("ck").innerHTML = "Включить переливание фона
кликабельно";
return false;
}
function check2() {
document.getElementById("ck").innerHTML = "Отключить переливание фона
кликабельно";
return false;
}
function changeText() {
var check = true;
if (check == true) {
check1();
check = false;
console.log("Successfully check = false");
}
else {
check2();
check = true;
console.log("Successfully check = true");
}
}

Well the if statement is wrong, you should have an ==, but before you do var check = true which will always lead to check be true.
Note: if you want to evaluate a variable to true, you can simply type if (check){}

Related

window.location.href does not redirect

my functions are as follows
<a onClick="check_claims(this)" type="button" href="javascript:void(0)" redirurl="www.facebook.com" >Invite</a>
function check_claims(ele){
var select_claims = document.getElementById('select_claims').value;
if (select_claims == '1') {
var result = confirm("do you wish to continue?");
if (!result) {
check_email_address();
return;
}
}
check_email_address();
window.location.href = ele.getAttribute('redirurl');
}
function check_email_address(){
if ('{{broker.email_address}}' == 'None') {
console.log('this worked till here');
window.location.href = 'www.google.com';
}
}
I just added the second function check_email_address. the function gets called and the log gets printed but the windows.location.href of this function does not get evaluated and the page keeps redirecting to url mentioned in the window.location.href of first function.
Try using return false; at the end of the handler.
You can refer to this question for more details.
EDIT: Try this please.
function check_claims(ele){
var select_claims = document.getElementById('select_claims').value;
if (select_claims == '1') {
var result = confirm("do you wish to continue?");
if (!result) {
check_email_address();
return;
}
}
var email_check = check_email_address();
if (!email_check) window.location.href = ele.getAttribute('redirurl');
}
function check_email_address(){
if ('{{broker.email_address}}' == 'None') {
console.log('this worked till here');
window.location.href = 'www.google.com';
return true;
}
return false;
}

How to validate form based on values and submit call out to another page accordingly?

How can I pause submission so that I can validate, check values, and possibly submit an xhtml callout based on the choices all before allowing the form to finally submit?
Have tried using various jquery methods found on here, using callbacks, setting timeouts, and holding in a while loop until everything's done. A lot of the alerts found in the code are only for troubleshooting/tracing purposes.
function completeTicket() {
alert("fnOpenDiag Called");
$("#dialog-confirm").html("Auto create return eTicket?");
// Define the Dialog and its properties.
$("#dialog-confirm").dialog({
resizable: false,
modal: true,
title: "Auto create return eTicket?",
height: 250,
width: 400,
buttons: {
"Yes": function () {
var quickissue = "Return <?php echo ($ticketRow['items_count'] >= 1 ? $ticketRow['items'] : 'Computer'); ?>";
var selectedLocation2 = <?php echo ($ticketRow['Location_ID'] == '' ? 0 : $ticketRow['Location_ID']); ?>;
xmlhttp=GetXmlHttpObject();
if (xmlhttp==null) {
alert ("This browser does not support XMLHTTP!");
}
var url="xhtmlCallOut_QuickEticket.php?callerID=pc_ticket_detail&selectedLocation_ID=" + selectedLocation2 + "&tboxIssue=" + quickissue;
xmlhttp.open("GET",url,false);
xmlhttp.send(null);
if (xmlhttp.readyState==4){
if (xmlhttp.responseText != 0){
alert(xmlhttp.responseText);
}
}
alert("ticket success");
return true;
$(this).dialog('close');
//callback(true);
//callback();
},
"No": function () {
return true;
$(this).dialog('close');
//callback(false);
//callback();
}
}
});
}
function checkForm() {
alert("checkform called");
if(document.getElementById('assocCompany').selectedIndex == 0) {
alert('Please associte this company with a known company name\nfrom the drop list.');
document.getElementById('assocCompany').focus();
e.preventDefault();
return false;
}
else if(document.getElementById('assignTech').selectedIndex == 0 && document.getElementById('status').selectedIndex >= 2){
alert('You must define a technician first!');
document.getElementById('assignTech').focus();
e.preventDefault();
return false;
}
else if(RegisterForm.elements['status'].value == 3 && RegisterForm.elements['tboxreaspend'].value.length < 3){
alert('You must give a reason for this ticket being changed to pending');
document.getElementById('tboxreaspend').focus();
e.preventDefault();
return false;
}
else if(RegisterForm.elements['tboxissue'].value.length < 3){
alert('You must give a description of the issue');
document.getElementById('tboxissue').focus();
e.preventDefault();
return false;
}
else {
pc_ticketdetail.actionbutton.disabled=true;
return false;
}
}
function showPendingReason() {
var y = document.getElementById("status");
var val = y.options[y.selectedIndex].value;
if (val == 3) {
$('#trReasPend').show();
} else {
$('#trReasPend').hide();
}
}
function submitForm() {
alert("submitform called");
var x = document.getElementById("status");
var valx = x.options[x.selectedIndex].value;
alert("statval is " + valx);
if (valx == 4) {
if (completeTicket()) {
e.preventDefault();
return false;
alert("complete ticket done");
} else {
e.preventDefault();
return false;
}
} else {
if (checkForm()) {
e.preventDefault();
return false;
alert("checkform done");
} else {
alert("checkform FALSE return");
e.preventDefault();
return false;
}
}
}
<div id="dialog-confirm"></div>
<form action="<?php $_SERVER['PHP_SELF']; ?>" name="pc_ticketdetail" id="pc_ticketdetail" method="post" onSubmit="return submitForm();">
<select name="status" id="status" onChange="javascript:showPendingReason();">
<option<?php if($ticketRow['status'] == 1){ echo ' selected'; } ?> value="1">New</option>
<option<?php if($ticketRow['status'] == 2){ echo ' selected'; } ?> value="2">Bench</option>
<option<?php if($ticketRow['status'] == 3){ echo ' selected'; } ?> value="3">Pending</option>
<option<?php if($ticketRow['status'] == 4){ echo ' selected'; } ?> value="4">Finished</option>
<?php if($ticketRow['status'] == 5){
echo '<option selected value="5">Closed/Deleted</option>';
} ?>
</select>
It currently seems to step through as expected except the "completeTicket" and "checkForm" functions are either not being called or not returning correctly. The form simply submits and closes when they should fail validation or open the modal dialogue and ask to create return ticket.
Take a look on the (async - await) function in javaScript.
async function
your checkForm() never return false so is your completeTicket() never return true. you can initially define a variable as false and make it true if it meets a specific condition then return the variable to the main function.
<script>
function c(){
let isTrue = false;
if(condition){
isTrue = true;
}
return isTrue;
}
function d(){
if(c()){
alert("c returned true");
} else{
alert("c returned false");
}
}
</script>
If you remove the alerts from under the return statements, that would help you in tracing the problem, because no code will run after you return from a function. Same thing for $(this).dialog('close').
And I think that you should capture the event object before using it in e.preventDefault() so try to remove the onSubmit attribute from the form and adding the listener through jQuery like so :
$(YOUR_FORM_SELECTOR).submit(function(e) {
// here you access to the e Object
})
I don't know if that related to the problem you have, Try describing what's happening exactly when you run the code.

Jquery .js file does not execute

Javascript code will not execute no matter what I do. I've tried using $(document).ready(function{..... without success.
Js file is supposed to support a submit button that as a result does nothing when being clicked.
Code in the HTML file:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Fit By Than </title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="css/themes/fitbythan.min.css" rel="stylesheet" />
<link href="css/themes/jquery.mobile.icons.min.css" rel="stylesheet" />
<link href="lib/jqm/jquery.mobile.structure-1.4.5.min.css" rel="stylesheet" />
<link href="css/app.css" rel="stylesheet" />
<script type="text/javascript" src="lib/jquery/2.1.4/jquery-2.1.4.min.js"></script>
<script type="text/javascript" src="js/settings.js"></script>
<script type="text/javascript" src="js/api-messages.js"></script>
<script type="text/javascript" src="js/sign-up.js"></script>
<script type="text/javascript" src="lib/jqm/jquery.mobile-1.4.5.min.js"></script>
</head>
Code in js file:
(function () {
var emailAddressIsValid = function (email) {
var re = /^(([^<>()[\]\\.,;:\s#\"]+(\.[^<>()[\]\\.,;:\s#\"]+)*)|(\".+\"))#((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
return re.test(email);
};
var passwordsMatch = function (password, passwordConfirm) {
return password === passwordConfirm;
};
var passwordIsComplex = function (password) {
// TODO: implement password complexity rules here. There should be similar rule on the server side.
return true;
};
$(document).delegate("#page-signup", "pagebeforecreate", function () {
var $signUpPage = $("#page-signup"),
$btnSubmit = $("#btn-submit", $signUpPage);
$btnSubmit.off("tap").on("tap", function () {
var $ctnErr = $("#ctn-err", $signUpPage),
$txtFirstName = $("#txt-first-name", $signUpPage),
$txtLastName = $("#txt-last-name", $signUpPage),
$txtEmailAddress = $("#txt-email-address", $signUpPage),
$txtPassword = $("#txt-password", $signUpPage),
$txtPasswordConfirm = $("#txt-password-confirm", $signUpPage);
var firstName = $txtFirstName.val().trim(),
lastName = $txtLastName.val().trim(),
emailAddress = $txtEmailAddress.val().trim(),
password = $txtPassword.val().trim(),
passwordConfirm = $txtPasswordConfirm.val().trim(),
invalidInput = false,
invisibleStyle = "bi-invisible",
invalidInputStyle = "bi-invalid-input";
// Reset styles.
$ctnErr.removeClass().addClass(invisibleStyle);
$txtFirstName.removeClass(invalidInputStyle);
$txtLastName.removeClass(invalidInputStyle);
$txtEmailAddress.removeClass(invalidInputStyle);
$txtPassword.removeClass(invalidInputStyle);
$txtPasswordConfirm.removeClass(invalidInputStyle);
// Flag each invalid field.
if (firstName.length === 0) {
$txtFirstName.addClass(invalidInputStyle);
invalidInput = true;
}
if (lastName.length === 0) {
$txtLastName.addClass(invalidInputStyle);
invalidInput = true;
}
if (emailAddress.length === 0) {
$txtEmailAddress.addClass(invalidInputStyle);
invalidInput = true;
}
if (password.length === 0) {
$txtPassword.addClass(invalidInputStyle);
invalidInput = true;
}
if (passwordConfirm.length === 0) {
$txtPasswordConfirm.addClass(invalidInputStyle);
invalidInput = true;
}
// Make sure that all the required fields have values.
if (invalidInput) {
$ctnErr.html("<p>Please enter all the required fields.</p>");
$ctnErr.addClass("bi-ctn-err").slideDown();
return;
}
if (!emailAddressIsValid(emailAddress)) {
$ctnErr.html("<p>Please enter a valid email address.</p>");
$ctnErr.addClass("bi-ctn-err").slideDown();
$txtEmailAddress.addClass(invalidInputStyle);
return;
}
if (!passwordsMatch(password, passwordConfirm)) {
$ctnErr.html("<p>Your passwords don't match.</p>");
$ctnErr.addClass("bi-ctn-err").slideDown();
$txtPassword.addClass(invalidInputStyle);
$txtPasswordConfirm.addClass(invalidInputStyle);
return;
}
if (!passwordIsComplex(password)) {
// TODO: Use error message to explain password rules.
$ctnErr.html("<p>Your password is very easy to guess. Please try a more complex password.</p>");
$ctnErr.addClass("bi-ctn-err").slideDown();
$txtPassword.addClass(invalidInputStyle);
$txtPasswordConfirm.addClass(invalidInputStyle);
return;
}
$.ajax({
type: 'POST',
url: FBT.Settings.signUpUrl,
data:"email=" + emailAddress + "&firstName=" + firstName + "&lastName=" + lastName + "&password=" + password + "&passwordConfirm=" + passwordConfirm,
success: function (resp) {
console.log("success");
if (resp.success === true) {
$.mobile.navigate("signup-succeeded.html");
return;
}
if (resp.extras.msg) {
switch (resp.extras.msg) {
case FBT.ApiMessages.DB_ERROR:
case FBT.ApiMessages.COULD_NOT_CREATE_USER:
// TODO: Use a friendlier error message below.
$ctnErr.html("<p>Oops! A problem occured while trying to register you. Please try again in a few minutes.</p>");
$ctnErr.addClass("bi-ctn-err").slideDown();
break;
case FBT.ApiMessages.EMAIL_ALREADY_EXISTS:
$ctnErr.html("<p>The email address that you provided is already registered.</p>");
$ctnErr.addClass("bi-ctn-err").slideDown();
$txtEmailAddress.addClass(invalidInputStyle);
break;
}
}
},
error: function (e) {
console.log(e.message);
// TODO: Use a friendlier error message below.
$ctnErr.html("<p>Oops! A problem occured while trying to register you. Please try again in a few minutes.</p>");
$ctnErr.addClass("bi-ctn-err").slideDown();
}
});
});
});
})();
Try this : If there any dependancy of mobile jquery then put it before sign-ip.js
<script type="text/javascript" src="lib/jquery/2.1.4/jquery-2.1.4.min.js"></script>
<script type="text/javascript" src="lib/jqm/jquery.mobile-1.4.5.min.js"></script>
<script type="text/javascript" src="js/settings.js"></script>
<script type="text/javascript" src="js/api-messages.js"></script>
<script type="text/javascript" src="js/sign-up.js"></script>
Also in your sign-up.js, for first and last line do following changes
(function ($) {
//your code
})(jQuery);
I could not check your html document or specified case but I think your jQuery library is not loaded yet.
$(document).ready(function(){
var emailAddressIsValid = function (email) {
var re = /^(([^<>()[\]\\.,;:\s#\"]+(\.[^<>()[\]\\.,;:\s#\"]+)*)|(\".+\"))#((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
return re.test(email);
};
var passwordsMatch = function (password, passwordConfirm) {
return password === passwordConfirm;
};
var passwordIsComplex = function (password) {
// TODO: implement password complexity rules here. There should be similar rule on the server side.
return true;
};
$(document).delegate("#page-signup", "pagebeforecreate", function () {
var $signUpPage = $("#page-signup"),
$btnSubmit = $("#btn-submit", $signUpPage);
$btnSubmit.off("tap").on("tap", function () {
var $ctnErr = $("#ctn-err", $signUpPage),
$txtFirstName = $("#txt-first-name", $signUpPage),
$txtLastName = $("#txt-last-name", $signUpPage),
$txtEmailAddress = $("#txt-email-address", $signUpPage),
$txtPassword = $("#txt-password", $signUpPage),
$txtPasswordConfirm = $("#txt-password-confirm", $signUpPage);
var firstName = $txtFirstName.val().trim(),
lastName = $txtLastName.val().trim(),
emailAddress = $txtEmailAddress.val().trim(),
password = $txtPassword.val().trim(),
passwordConfirm = $txtPasswordConfirm.val().trim(),
invalidInput = false,
invisibleStyle = "bi-invisible",
invalidInputStyle = "bi-invalid-input";
// Reset styles.
$ctnErr.removeClass().addClass(invisibleStyle);
$txtFirstName.removeClass(invalidInputStyle);
$txtLastName.removeClass(invalidInputStyle);
$txtEmailAddress.removeClass(invalidInputStyle);
$txtPassword.removeClass(invalidInputStyle);
$txtPasswordConfirm.removeClass(invalidInputStyle);
// Flag each invalid field.
if (firstName.length === 0) {
$txtFirstName.addClass(invalidInputStyle);
invalidInput = true;
}
if (lastName.length === 0) {
$txtLastName.addClass(invalidInputStyle);
invalidInput = true;
}
if (emailAddress.length === 0) {
$txtEmailAddress.addClass(invalidInputStyle);
invalidInput = true;
}
if (password.length === 0) {
$txtPassword.addClass(invalidInputStyle);
invalidInput = true;
}
if (passwordConfirm.length === 0) {
$txtPasswordConfirm.addClass(invalidInputStyle);
invalidInput = true;
}
// Make sure that all the required fields have values.
if (invalidInput) {
$ctnErr.html("<p>Please enter all the required fields.</p>");
$ctnErr.addClass("bi-ctn-err").slideDown();
return;
}
if (!emailAddressIsValid(emailAddress)) {
$ctnErr.html("<p>Please enter a valid email address.</p>");
$ctnErr.addClass("bi-ctn-err").slideDown();
$txtEmailAddress.addClass(invalidInputStyle);
return;
}
if (!passwordsMatch(password, passwordConfirm)) {
$ctnErr.html("<p>Your passwords don't match.</p>");
$ctnErr.addClass("bi-ctn-err").slideDown();
$txtPassword.addClass(invalidInputStyle);
$txtPasswordConfirm.addClass(invalidInputStyle);
return;
}
if (!passwordIsComplex(password)) {
// TODO: Use error message to explain password rules.
$ctnErr.html("<p>Your password is very easy to guess. Please try a more complex password.</p>");
$ctnErr.addClass("bi-ctn-err").slideDown();
$txtPassword.addClass(invalidInputStyle);
$txtPasswordConfirm.addClass(invalidInputStyle);
return;
}
$.ajax({
type: 'POST',
url: FBT.Settings.signUpUrl,
data:"email=" + emailAddress + "&firstName=" + firstName + "&lastName=" + lastName + "&password=" + password + "&passwordConfirm=" + passwordConfirm,
success: function (resp) {
console.log("success");
if (resp.success === true) {
$.mobile.navigate("signup-succeeded.html");
return;
}
if (resp.extras.msg) {
switch (resp.extras.msg) {
case FBT.ApiMessages.DB_ERROR:
case FBT.ApiMessages.COULD_NOT_CREATE_USER:
// TODO: Use a friendlier error message below.
$ctnErr.html("<p>Oops! A problem occured while trying to register you. Please try again in a few minutes.</p>");
$ctnErr.addClass("bi-ctn-err").slideDown();
break;
case FBT.ApiMessages.EMAIL_ALREADY_EXISTS:
$ctnErr.html("<p>The email address that you provided is already registered.</p>");
$ctnErr.addClass("bi-ctn-err").slideDown();
$txtEmailAddress.addClass(invalidInputStyle);
break;
}
}
},
error: function (e) {
console.log(e.message);
// TODO: Use a friendlier error message below.
$ctnErr.html("<p>Oops! A problem occured while trying to register you. Please try again in a few minutes.</p>");
$ctnErr.addClass("bi-ctn-err").slideDown();
}
});
});
});
});

only start functions when all previous functions returned false

I'm new at javascripts so forgive me if this seems obvious but what I want is to start a second function oly if all the condtitions of the previous function actions returned false
function validateForm()
{
var file = document.getElementById('file');
if (file.files[0].size >= 11000000) {
alert('File too Big');
return false;
}
var x=document.forms["myForm"]["title"].value;
if (x==null || x==""){
alert("First name must be filled out");
return false;
}
// if both returned false then start this function:
function start_Uploading(){
document.getElementById('message').innerHTML = 'Loading...';
return true;
}
the html:
<input type='submit' onclick="return validateForm();">
Your return values end the function call. You just want to set a variable to see if the input is valid. You can then check and see if the isValid is true, and call your function from there.
Also worth noting in your original code that
function start_Uploading(){...}
doesn't actually run the function, it just defines it. You need start_uploading() to execute the function.
function validateForm()
{
var isValid = true;
var file = document.getElementById('file');
if (file.files[0].size >= 11000000) {
alert('File too Big');
isValid=false;
}
var x=document.forms["myForm"]["title"].value;
if (x==null || x==""){
alert("First name must be filled out");
isValid=false;
}
// if both returned false then start this function:
function start_Uploading(){
document.getElementById('message').innerHTML = 'Loading...';
return true;
}
if(isValid){
start_Uploading();
}
}
You can only return once from a function, so you would have to return a binary AND of the false values:
function validateForm()
{
var condition1;
var condition2;
if(...) condition1 = false;
if(...) condition2 = false;
return (condition1 && condition2);
}
This is how you would start a function if validateForm returned false:
if(!validateForm())
{
// Execute your function
start_Uploading();
}
Call this function, it will check the first function and second function values and if they are returning false, then start_Uploading() function will execute:
function sampleFunction() {
if(!firstFunction() && !secondFunction()){
start_Uploading();
}
}
In jQuery way:
<script type="text/javascript">
$("#myForm").submit(function() {
if ($("#file")[0].files[0].size >= 11000000) {
alert('File too Big');
return false;
}
if ($("#myForm input[name=title]").attr("value") == ""){
alert("First name must be filled out");
return false;
}
$('#message').html('Loading...');
return true;
})
</script>
<form id="myForm">
<input type='submit'>
</form>

Why does my form still submit when my javascript function returns false?

Here is my Javascript formvalidator function:
function companyName() {
var companyName = document.forms["SRinfo"]["companyName"].value;
if (companyName == ""){
return false;
} else {
return true;
}
}
function companyAdd() {
var companyAdd1 = document.forms["SRinfo"]["companyAdd1"].value;
if (companyAdd1 == ""){
return false;
} else {
return true;
}
}
function companyCity() {
var companyCity = document.forms["SRinfo"]["companyCity"].value;
if (companyCity == ""){
return false;
} else {
return true;
}
}
function companyZip() {
var companyZip = document.forms["SRinfo"]["companyZip"].value;
if (companyZip == ""){
return false;
} else {
return true;
}
}
function enteredByName() {
var enteredByName = document.forms["SRinfo"]["enteredByName"].value;
if (enteredByName == ""){
return false;
} else {
return true;
}
}
function dayPhArea() {
var dayPhArea = document.forms["SRinfo"]["dayPhArea"].value;
if (dayPhArea == ""){
return false;
}
}
function dayPhPre() {
var dayPhPre = document.forms["SRinfo"]["dayPhPre"].value;
if (dayPhPre == ""){
return false;
} else {
return true;
}
}
function dayPhSub() {
var dayPhSub = document.forms["SRinfo"]["dayPhSub"].value;
if (companyAdd1 == ""){
return false;
} else {
return true;
}
}
function validateForm() {
if (companyName() && companyAdd() && companyCity() && companyZip() && enteredByName() && dayPhArea() && dayPhPre() && dayPhSub()) {
return true;
} else {
window.alert("Please make sure that all required fields are completed.");
document.getElementByID("companyName").className = "reqInvalid";
companyName.focus();
return false;
}
}
Here are all of my includes, just in case one conflicts with another (I am using jquery for their toggle()):
<script type="text/javascript" src="formvalidator.js"></script>
<script type="text/javascript" src="autoTab.js"></script>
<?php
require_once('mobile_device_detect.php');
include_once('../db/serviceDBconnector.php');
$mobile = mobile_device_detect();
if ($mobile) {
header("Location: ../mobile/service/index.php");
if ($_GET['promo']) {
header("Location: ../mobile/service/index.php?promo=".$_GET['promo']);
}
}
?>
<script src="http://code.jquery.com/jquery-1.7.1.js"></script>
Here is my form tag with the function returned onSubmit:
<form method="POST" action="index.php" name="SRinfo" onsubmit="return validateForm();">
The validation works perfectly, I tested all fields and I keep getting the appropriate alert, however after the alert the form is submitted into mysql and sent as an email. Here is the code where I submit my POST data.
if($_SERVER['REQUEST_METHOD']=='POST') {
// Here I submit to Mysql database and email form submission using php mail()
It would seem to me that this line is likely blowing up:
companyName.focus();
The only definition I see for companyName is the function. You can't call focus on a function.
This blows up so the return false is never reached.
I would comment out all the code in the validation section and simply return false. If this stops the form from posting then there is an error in the actual code performing the validation. Add each part one at a time until the error is found.
My guess is the same as James suggests that you are calling focus on the function 'companyName'. The line above this seems to be trying to get the element from the document with the same name but you are not assigning this to a variable so that you can call focus on it.

Categories

Resources