I have two functions that I would like to combine into one. Is it possible to combine...
$(document).ready(function () {
$(".jobtype").change(function () {
if ($("select[name='jobtype']").val() != "Low Budget") {
// something happens
}
});
});
and this...
$(document).ready(function () {
$(document).on('keyup', function (evt) {
if (evt.keyCode == 27) {
// same thing happens
}
});
});
so that they work for both change() and keyup?
EDIT: Sorry I wrote this post really late at night so maybe wasn't explaining myself properly.
I have a form, that when the option "Low Budget" is selected from a drop down select list, that a function runs that changes a bunch of stuff on the page.
However, if the "Low Budget" option is deselected, then another script runs that undoes the changes and returns the page to its original form. This code to return it to original form is maybe 30 lines long.
I would like the same piece of code to run, if the user presses ESC and closes out of the form.
It seems strange to have the same function written out twice, so am wondering what is correct and most efficient way to code this. Part of me thinks that I could have the 30 lines of code written inside of something like
function doSomething() {
// 30 lines of code
}
and then inside the two events have:
$(document).ready(function () {
$(".jobtype").change(function () {
if ($("select[name='jobtype']").val() != "Low Budget") {
doSomething();
}
});
});
and
$(document).ready(function () {
$(".jobtype").change(function () {
if ($("select[name='jobtype']").val() != "Low Budget") {
doSomething();
}
});
});
However I am unsure of the correct way to structure code.
Thanks again