[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

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

Posted on 2004-10-31
6
Medium Priority
?
271 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
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…

650 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