Reputation: 771
I have a header view which is loaded in every view. I have a jquery function in header view and want to use that jquery function in another views jquery function.
Header view jquery function:
$('#myAccount').click( function() {
loadPopupBox();
$('.login_pop_right').fadeTo('slow',1);
$("#mdhemadd").attr('disabled',false);
$("#mdhpass").attr('disabled',false);
});
I want to access it another views jquery function:
$('#shortlist').click(function(){
var userid = $('#userid').val();
var dealid = $('#dealid').val();
if(userid!=''){
$.ajax({
type: "POST",
url: "/packagedetails/shortlistdeal",
data: "userid=" + userid+"&dealid="+dealid,
// data: form_data,
success: function(data) {
var obj = jQuery.parseJSON(data);
if(obj==true)
{
loadShortlistPopupBox();
$('#shortlistmsg').empty();
var html='<span class="messageicon"></span><p>Deal shortlisted sucessfullly.</p>';
$('#shortlistmsg').append(html);
// alert("Deal shortlisted sucessfullly");
}
else
{
loadShortlistPopupBox();
$('#shortlistmsg').empty();
var html='<span class="messageicon"></span><p>This deal cannot be shortlisted.Please check your account for your <a href="/myaccount">shortlisted deals</a>.</p>';
$('#shortlistmsg').append(html);
// alert("This deal cannot be shortlisted.Please check your account for your shortlisted deals.");
}
}
});
}
else
{
alert("sd");
$('#myAccount').click();
}
});
How to do it?
Thanks,
Upvotes: 0
Views: 898
Reputation: 852
Create one file with script.js, add this code in it. then include that in every page. so it works
Upvotes: 1
Reputation: 1123
if the header view is loaded in every page, the click event is registering every click already. Instead of creating a new click event in the else statement, pack the code in the click event into a function.
$('#myAccount').click( function() {
byClick();
});
function byClick()
{
loadPopupBox();
$('.login_pop_right').fadeTo('slow',1);
$("#mdhemadd").attr('disabled',false);
$("#mdhpass").attr('disabled',false);
}
In the else statement:
else{
byClick();
}
Upvotes: 0