Link to home
Start Free TrialLog in
Avatar of movieprodw
movieprodw

asked on

javascript, onsubmit return

Hello,

I have the below functions and I want to add them into one function, onsubmit check form the if true then activate div.

Thanks for any help.
<script language="JavaScript" type="text/javascript">
<!--
function checkform ( form )
{
  if (form.userId.value == "" || form.firstname.value == "" || form.lastname.value == "" || form.phonenumber.value == "" || form.price.value == "" || form.zip.value == "" || form.title.value == "" || form.build_year.value == "" || form.sq_ft.value == "" || form.prop_desc.value == "") {
    alert( "Please complete all of the required* fields." );
    return false ;
  }
  // ** END **
  return true ;
}
//-->
</script>

<script type="text/javascript">
function onSubmitButton(){
        document.getElementById("submitButtonDiv").style.display = "none";    
    
    if (navigator.appName == "Microsoft Internet Explorer") {
    document.getElementById("progressBar").innerHTML = "";
    document.getElementById("progressBar").style.display = "block";
    document.getElementById("progressBar").innerHTML = "<img src='/img/ajax-loader.gif' alt='Progress Bar'>";
    } else {
    document.getElementById("progressBar").style.display = "block";        
    }
}
</script>

Open in new window

Avatar of HainKurt
HainKurt
Flag of Canada image

try this
<script language="JavaScript" type="text/javascript">
<!--
function checkform(form)
{
  if (form.userId.value == "" || form.firstname.value == "" || form.lastname.value == "" || form.phonenumber.value == "" || form.price.value == "" || form.zip.value == "" || form.title.value == "" || form.build_year.value == "" || form.sq_ft.value == "" || form.prop_desc.value == "") {
    alert( "Please complete all of the required* fields." );
    return false;
  }
  return true ;
}

function onSubmitButton(){
  if (!checkform(document.forms["yourFormID"])) return false;
  //if (!checkform(document.forms[0])) return false;
  //if (!checkform(document.formName)) return false;
  //if (!checkform(document.getElementById("formID"))) return false;
  document.getElementById("submitButtonDiv").style.display = "none";    
    
  if (navigator.appName == "Microsoft Internet Explorer") {
  document.getElementById("progressBar").innerHTML = "";
  document.getElementById("progressBar").style.display = "block";
  document.getElementById("progressBar").innerHTML = "<img src='/img/ajax-loader.gif' alt='Progress Bar'>";
  } else {
      document.getElementById("progressBar").style.display = "block";        
  }
}
</script>

Open in new window

Avatar of movieprodw
movieprodw

ASKER

That did check the info but did not make the second function work.

Here is what I have for the form
<form action="./processlisting.php" method="post" enctype="multipart/form-data" onSubmit="return checkform(this)">
ASKER CERTIFIED SOLUTION
Avatar of HainKurt
HainKurt
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
how do you call this function? onSubmitButton
is there a button that calls this? if yes post the code...
Thank you
NOTE that the correct answer has an error:

  }
}
</script>

should be

  }
}
-->
</script>