Cancel href via an onclick
I have a link created by ASP.NET that is used to submit my form -
<a href="javascript:generatedfunction();">Click Me</a>
I desired to be able to trigger an event on submit of the form. However since the form got submitted through javascript, I could not just associate the onSubmit of the form (did not be in function ) but I was able to insert my own generated function that triggers first in the onclick-
<a onclick="myfunction();" href="javascript:generatedfunction();">
And it is working fine now .So I wanted to ask that how/what code should be added that can be able to restrict the form submission.
Cancel href via an onclick
This is very interesting case because users are always asking about the solution for loading the generated form. But if you need to as you stated in your post then you can do it as. Return true from the onclick to submit the form, return false otherwise:
Code:
<a onclick="return myfunction();" href="javascript:generatedfunction();">
function myfuncion()
{
if ( some condition )
return true;
else
return false;
}
Cancel href via an onclick
That's right Zecho , I always seen that users need to know about the solution for loading issues but I need to ask just opposite because I am practicing on this..
By the way, I am glad to know that you all viewed my problems and considered the effective solution, But the solution that you have given to me. According to me, I have tried this already but after your suggestion . I will try it again ...
Thanks for all this !!
Cancel href via an onclick
This is very simple task and you can do to change some lines of code in your function and you need to adjust the false and true according to the need of execution. You need to use javascript function and use return false
Code:
<script language "JavaScript" >
function myfunc()
{
return false;
}
</script>
Cancel href via an onclick
Hello dear all,
Thanks for your support and now I have tried to do the same thing again. I put just "return false;" no if clauses or anything - to guarantee it was returning false.
So my created and coded function looks like this :
-------------------------------------
function myfunction()
{
alert("here");
return false;
}
-----------------------------------
The alert indicates me the function was firing. But it still fired the created function next.
Re: Cancel href via an onclick
Now, you got it properly that you can use the return to manage the loading of form. One thing more, don't forget to add the proper adjustment of values at proper place and you need to add return with the onclick event and that would be as follows -
Code:
<a onclick="return myfunction();" href="javascript:generatedfunction();">