NewBie Question, jQuery: How can we implement if...else logic and call function
Posted
by Rachel
on Stack Overflow
See other posts from Stack Overflow
or by Rachel
Published on 2010-04-11T22:38:27Z
Indexed on
2010/04/11
22:43 UTC
Read the original article
Hit count: 303
jQuery
|JavaScript
I am new to jQuery and so don't mind this question if it sounds stupid but here is something that I am trying to do :
I have 3 functions like:
AddToCart Function which adds item to the shopping cart:
//offer_id is the offer which we are trying to add to cart.
addToCart: function(offer_id)
{
this.submit({action: 'add', 'offer_id': offer_id}, {'app_server_url': this.app_server_url});
},
RemoveFromCart which removes data from the cart
//target is link clicked and event is the click event.
removeFromCart: function(target, event)
{
this.uniqueElmt('cart_table').find('.sb_item_remove').unbind('click');
var offer_id = $(target).parent().find('.offer_id').html();
this.submit({action: 'remove', 'offer_id': offer_id, 'next_action': this.config.current_action}, {'app_server_url': this.app_server_url});
},
Get the current state of the cart
//return string which represents current state of cart.
getCartItems: function()
{
return this.contents;
}
Now I am trying to do 3 things:
- if there is no
content
in cart andaddToCart
is called thansome action
, so basically here we need to check the current state of cart and that is obtained by callinggetCartItems
and if it isNull
and than ifaddToCart
is called than we performsome action
- if there is
content
in the cart andaddToCart
is called thansome action
,so basically here we need to check the current state of cart and that is obtained by callinggetCartItems
and check if it isNull
or not and than ifaddToCart
is called than we performsome action
if we had some content in the cart. - if there is
content
in the cart andremoveFromCart
is calledsome action
, so basically here we need to check the current state of cart and that is obtained by callinggetCartItems
and if it is not Null and ifremoveFromCart
is called than we performsome action
Pseudocode of what I am trying to do:
if there is no content in cart
and addToCart is called than
$(document).track(
{
'module' : 'Omniture',
'event' : 'instant',
'args' :
{
'linkTrackVars' : 'products,events',
'linkTrackEvents' : 'scAdd,scOpen',
'linkType' : 'o',
'linkName' : 'Cart : First Product Added' // could be blank, but can include event name as added feature
'svalues' :
{
'products' : ';OFFERID1[,;OFFERID2]',
'events' : 'scAdd,scOpen',
},
}
'defer' : '0'
}
);
if there is content in the cart
and addToCart is called than
$(document).track(
{
'module' : 'Omniture',
'event' : 'instant',
'args' :
{
'linkTrackVars' : 'products,events',
'linkTrackEvents' : 'scAdd',
'linkType' : 'o',
'linkName' : 'Cart : Product Added' // could be blank, but can include event name as added feature
'svalues' :
{
'products' : ';OFFERID1[,;OFFERID2]',
'events' : 'scAdd',
},
},
'defer' : '0'
}
);
if there is content in the cart
and removeFromCart is called
$(document).track(
{
'module' : 'Omniture',
'event' : 'instant',
'args' :
{
'linkTrackVars' : 'products,events',
'linkTrackEvents' : 'scRemove',
'linkType' : 'o',
'linkName' : 'Cart : Product Removed' // could be blank, but can include event name as added feature
'svalues' :
{
'products' : ';OFFERID1[,;OFFERID2]',
'events' : 'scRemove',
},
}
'defer' : '0'
}
);
My basic concern is that am complete newbie to jQuery and JavaScript and so am not sure how can I implement if...else logic and how can I call a funtion using jQuery/JavaScript.
© Stack Overflow or respective owner