b_rajathilagam
asked on
How to stop submission of form while pressing the submit button?
Hi,
I wants to stop the submission of form while pressing a submit button. I will call a function to do some operation while pressing the submit button. i don't want to submit the form instead i wants to call a function.
how can i do this through javascript?
Thanks.
<script>
function someCalculation(obj)
{
notCalculated=true;
if(notCalculated)
{
alert("calculation");
return false;
}
return true;
}
</script>
<form action=http://www.google.com/search/? onsubmit="return someCalculation(this)">
<input type=text name=q value=hurra>
<input type=submit>
</form>
function someCalculation(obj)
{
notCalculated=true;
if(notCalculated)
{
alert("calculation");
return false;
}
return true;
}
</script>
<form action=http://www.google.com/search/? onsubmit="return someCalculation(this)">
<input type=text name=q value=hurra>
<input type=submit>
</form>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
function t() not function () in 2nd line (still works though)
Hi
If you just want a button to call a function and not to submit the form, then you can just use input type ="button" instead of input type ="submit". If you however would like to submit through the function and can use form_name.submit();
EXAMPLE:
************************** ********** ********** *****
<script language ="javascript">
function some_func()
{
alert ("Some function");
//form1.submit(); //this submits the form
}
</script>
<form name="form1" action="" method ="post">
<input type = "button" name = "btn1" value = "click button">
</form>
If you just want a button to call a function and not to submit the form, then you can just use input type ="button" instead of input type ="submit". If you however would like to submit through the function and can use form_name.submit();
EXAMPLE:
**************************
<script language ="javascript">
function some_func()
{
alert ("Some function");
//form1.submit(); //this submits the form
}
</script>
<form name="form1" action="" method ="post">
<input type = "button" name = "btn1" value = "click button">
</form>
why the B?
<form action="http://google.com/search" onsubmit="alert('hello world');return false">
<input type='text' name=q>
<input type='submit'>
</form>