php - Calling multiple functions on "Onsubmit" - Stack Overflow

I have a form through which i am finding distance between two locations.right now my form works fine.i

I have a form through which i am finding distance between two locations. right now my form works fine.i have used.

<form method="get" name="f1" id="f1" class="formular" action="findcars.php" onsubmit="showLocation(); return false;">

Now i want to validate all form inputs.. so i have added the function validate(); like this

<form method="get" name="f1" id="f1" class="formular" action="findcars.php" onsubmit="validate(); showLocation(); return false;">  

But this is not working..pls..help, how should i call this validate() function.

Thanks.

I have a form through which i am finding distance between two locations. right now my form works fine.i have used.

<form method="get" name="f1" id="f1" class="formular" action="findcars.php" onsubmit="showLocation(); return false;">

Now i want to validate all form inputs.. so i have added the function validate(); like this

<form method="get" name="f1" id="f1" class="formular" action="findcars.php" onsubmit="validate(); showLocation(); return false;">  

But this is not working..pls..help, how should i call this validate() function.

Thanks.

Share Improve this question asked Mar 13, 2013 at 11:28 DevDev 4796 silver badges15 bronze badges 4
  • try this javascript:validate(); – Sumit Bijvani Commented Mar 13, 2013 at 11:30
  • @Sumit yes,i have made validate(); , but the problem is that script doesn't call that function – Dev Commented Mar 13, 2013 at 11:32
  • @SumitBijvani the prefix javascript: in on… attributes is a mistake. It's never needed, it doesn't do anything (it doesn't cause syntax error only because it happens to match break/continue labels syntax) – Kornel Commented Mar 13, 2013 at 11:35
  • can you please write the code here for function validate() – Praveen kalal Commented Mar 13, 2013 at 11:45
Add a ment  | 

6 Answers 6

Reset to default 1

Maybe you could try this

<form method="get" name="f1" id="f1" class="formular" action="findcars.php" onsubmit="myFunction(); return false;">

<script>
    myFunction function () {
    validate(); 
    showLocation();
}
</script>

try doing

validate() && showLocation();

or, calling one master function which then runs a chain:

masterFunction();

function masterFunction() {
  validate();
  showLocation();
}

Try this

<form method="get" name="f1" id="f1" class="formular" action="findcars.php" onsubmit="validate(); showLocation(); return false;">  
    <button id="search-submit" type="submit">Search</button>
</form>

Javascript

function validate(){
    alert('validate');
}
function showLocation(){
    alert('Location');
}

do in this way..

<form method="get" name="f1" id="f1" class="formular" action="findcars.php" onsubmit="return myvalidations();">

function myvalidations() {
validate(); 
showLocation();
}

Arrange functions like this:

<input type="button" onclick="function1();function2();" value="Call2Functions" />

  function func1(){
     //--- some logic
     func2();
   }

   function func2(){
    //--- some logic
   }

First call only validate() method if return true then call second method inside it. like below

function validate(){
// ok is output of your validate method whether true or false
if(ok){
showLocation();
}
else{
return false;
}
}

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745153167a4613958.html

相关推荐

  • php - Calling multiple functions on &quot;Onsubmit&quot; - Stack Overflow

    I have a form through which i am finding distance between two locations.right now my form works fine.i

    2小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信