Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Aug 2002
    Posts
    86
    Thanks
    2
    Thanked 1 Time in 1 Post

    Activate javascript from another javascript snipnet

    Hi Guys I am trying to modify the functionality of my page. I want to be able to activate this piece of code using another javascript function.

    This is the code I want to activate:

    Code:
    <script type="text/javascript"><!--
    $('#button-cart').bind('click', function() {
    	$.ajax({
    		url: 'index.php?route=checkout/cart/update',
    		type: 'post',
    		data: $('.product-info input[type=\'text\'], .product-info input[type=\'hidden\'], .product-info input[type=\'radio\']:checked, .product-info input[type=\'checkbox\']:checked, .product-info select, .product-info textarea, .date_data input[type=\'text\']'),
    		dataType: 'json',
    		success: function(json) {
    			$('.success, .warning, .attention, information, .error').remove();
    			
    			if (json['error']) {
    				if (json['error']['warning']) {
    					$('#notification').html('<div class="warning" style="display: none;">' + json['error']['warning'] + '<img src="catalog/view/theme/default/image/close.png" alt="" class="close" /></div>');
    				
    					$('.warning').fadeIn('slow');
    				}
    				
    				for (i in json['error']) {
    					$('#option-' + i).after('<span class="error">' + json['error'][i] + '</span>');
    				}
    			}	 
    						
    			if (json['success']) {
    				$('#notification').html('<div class="success" style="display: none;">' + json['success'] + '<img src="catalog/view/theme/default/image/close.png" alt="" class="close" /></div>');
    					
    				$('.success').fadeIn('slow');
    					
    				$('#cart_total').html(json['total']);
    				
    				$('html, body').animate({ scrollTop: 0 }, 'slow'); 
    			}	
    		}
    	});
    });
    //--></script>
    And this is how I want the format of the function to be:

    function testsession() {
    if there is a session called 'hiredate' {
    activate the script above
    }
    else {
    var el = document.getElementById("product_data");
    }
    }


    I just dont know how to write this in javascript

    Could you help me if possible please

  • #2
    Senior Coder
    Join Date
    Dec 2010
    Posts
    2,396
    Thanks
    12
    Thanked 569 Times in 562 Posts
    What do you mean by "activate"? A script is "active" by default as soon as it is loaded. Do you mean you want to EXECUTE what is inside the .bind(function()) without actually clicking anywhere?


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •