Change Value Of Onclick Function Vars
I have the onClick function attached to a button. I want to be able to change the function var from 'create' to 'update' on the page load and through other functions. I have tried
Solution 1:
$("#save_customer").click(function(){
customer_crud("read");
});
Is how you would do this.
EDIT:
$("#save_customer").click(function(){
customer_crud("update");
});
In jQuery you can set the value of the "onClick" attribute/event with .click(function(){/* Attribute content */});
Solution 2:
Don't use inline handlers if possible. They don't get proper scope, and also rely on the highly-frowned upon eval
to do their work.
Instead, in your .js
file, you can just do this:
var action = 'create';
$('#save_customer').click(function() {
customer_crud(action);
action = 'update';
});
The first time the handler is invoked it'll do create
, and then subsequently do an update
.
I put a working demo at http://jsfiddle.net/QzaXU/
Post a Comment for "Change Value Of Onclick Function Vars"