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:
inon…
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
6 Answers
Reset to default 1Maybe 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;
}
}