SO fiddle

Test Fiddle mainly for SO Questions

by Nick Craver

HTML

<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.4/themes/overcast/jquery-ui.css">
<a href="#" id="p1">click this to change p1.x</a>
<a href="#" id="p2">click this to change p2.x</a>

<input id="p1_val" value="">
<input id="p2_val" value="">

JavaScript

a = function(id) {

    this.inputid = id+'_val';
    var othis = this;
    $('#'+id).click(function(){
        othis.x += 1;
        $('#'+othis.inputid).val(othis.x);
    });

}


p1 = new a('p1');
p1.x=1;
p2 = new a('p2');
p2.x=1;