?
Solved

How to stop submission of form while pressing the submit button?

Posted on 2004-10-31
6
Medium Priority
?
272 Views
Last Modified: 2012-05-05

 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.
0
Comment
Question by:b_rajathilagam
6 Comments
 
LVL 31

Expert Comment

by:GwynforWeb
ID: 12458410
try this

<form action="http://google.com/search" onsubmit="alert('hello world');return false">
 <input type='text' name=q>
 <input type='submit'>
</form>
0
 
LVL 25

Expert Comment

by:devic
ID: 12458414
<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>
0
 
LVL 31

Accepted Solution

by:
GwynforWeb earned 750 total points
ID: 12458426
or this


<input type='button' value='Enable Submit' onclick="document.f1.onsubmit=function s(){return true}"><br>
<input type='button' value='Disable Submit' onclick="document.f1.onsubmit=function (){alert('hello world');return false}"><p>

<form name=f1 action="http://google.com/search" onsubmit="alert('hello world');return false">
 <input type='text' name=q>
 <input type='submit'>
</form>
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
LVL 31

Expert Comment

by:GwynforWeb
ID: 12458456
function t()   not    function ()       in 2nd line (still works though)
0
 
LVL 12

Expert Comment

by:minichicken
ID: 12458467
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>
0
 
LVL 7

Expert Comment

by:Xxavier
ID: 12460427
why the B?
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses how to implement server side field validation and display customized error messages to the client.
A while back, I ran into a situation where I was trying to use the calculated columns feature in SharePoint 2013 to do some simple math using values in two lists. Between certain data types not being accessible, and also with trying to make a one to…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

607 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question