How to call java script on button click event which handles event to add new row?
I have a button which adds new row in grid view at button click event. A row contains two text boxes and two drop down lists. But before adding new row I 开发者_StackOverflow中文版want to check if all controls in the first rows are filled or not. so for that I want to call java script on button click event. So how can I call java script on button which already handles an event new row in grid view?
You can define a javascript function which will check if all controls are filled and then if the requirements are accomplished to add a new row.
Ex:
function example()
{
if(controls filled)
add a new row;
}
then
<button type="button" onclick="example()">Click Me!</button>
The solution is to chain the calls. There are two ways to do this:
You can use the
onclick
property of the button in your function definition:function chainOnClick(button, func) { var origFunc = button.onclick; var tmp = function(e) { if(func(e)) { return origFunc(e); } return false; } button.onclick = tmp; }
Note that I've found that unreliable if there is no
onclick
installed; for some reason, the pattern doesn't work with the browser's default "onclick" handler.You can move the code that handles the click into a function (which you probably already have). Now you write a validation function and install this new click handler:
function validatedOnClick(e) { if(validateLastRow(e)) { return originalClickHandler(e); } return false; }
精彩评论