Hello and welcome to our community! Is this your first visit?
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
    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:

    <script type="text/javascript"><!--
    $('#button-cart').bind('click', function() {
    		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>');
    				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>');
    				$('html, body').animate({ scrollTop: 0 }, 'slow'); 
    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
    Thanked 570 Times in 563 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