combining two jquery functions

function altcat(id) {
        $ogzu = id;
    }       
    function okaycity(id) {
        jQuery("#okay").load("ajax_post_category.php?okay="+id+"");
        $ugur = id;
    }

how can i combine these two functions? i want them to work like as one function. i tried so many ways, however couldnt done it.i googled, couldnt find a way. can anyone save me? regards

Answers


function altcat(id) {
    $ogzu = id;
}       
function okaycity(id) {
    jQuery("#okay").load("ajax_post_category.php?okay="+id+"");
    $ugur = id;
}

function combined(id) {
    altcat(id);
    okaycity(id);
}

I'm confused :-S


I may be misunderstanding the question:

function combinedVersion(id) {
    $ogzu = id;
    jQuery("#okay").load("ajax_post_category.php?okay="+id+"");
    $ugur = id;
}

If you want to preserve their earlier names (because something is calling them by that name, and you can't update it to use a new name), you can add this to the above:

var altcat = combinedVersion;
var okaycity = combinedVersion;

Then, calling altcat(), okaycity(), or combinedVersion() will all call the same function. You will want to make sure that the two var statements there are above things that may use them. At the top of the function (if this is within a function) or page (if it's at global scope) would be best.

So if this is at global scope:

<script type='text/javascript'>
var altcat = combinedVersion;
var okaycity = combinedVersion;
function combinedVersion(id) {
    $ogzu = id;
    jQuery("#okay").load("ajax_post_category.php?okay="+id+"");
    $ugur = id;
}
</script>

...or if it's inside a function:

function foo() {
    var altcat = combinedVersion;
    var okaycity = combinedVersion;
    function combinedVersion(id) {
        $ogzu = id;
        jQuery("#okay").load("ajax_post_category.php?okay="+id+"");
        $ugur = id;
    }
}

Need Your Help

Query SQL Server from SPSS how to connect

sql-server-2008 odbc driver spss

I am at a total loss on how to do what I think is a fairly simple and standard task:

game development for any OS platform

android windows lua game-engine

Thanks the question was closed and I knew the ANSWER! ..

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.