I have a link with id="something"
:
html
<a id="something" onclick="getReturnValue()"> Something </a>
javascript
function getReturnValue(){
//some validation
if(validation fails){
return false;
}else{
return true;
}
}
I need to get the return value when I use:
$("#something").click();
How can I get the return value for the event ?
Already onclick function is mentioned in the html tag. I wanted to use:
$("#something").click();
and from that I wanted to get return value.
As I have to use it in multiple place, I dont want to write getReturnValue()
method again and again like:
click(function(){ getReturnValue() })
I need to do this
if($("#something").click() == true){
form.submit();
}
click() will call getReturnValue() which will do some validation. If the validation fails, it return false and I need not submit the form. If validation is true, I need to submit the form
do_action
) are a couple notable examples. It is more applicable with custom events (.trigger('some_event')
) than with DOM events. I like to trigger custom events before+after AJAX calls so different components can hook into the event, possibly modify the data, and possibly alter the resulting action. For example, my default response to an ajax call might be to reload the page but in certain situations, I may want to redirect instead.