Jump to content

nogray

Members
  • Posts

    930
  • Joined

  • Last visited

Posts posted by nogray

  1. You are going the wrong way about setting this. First, there is no "options" in the button element, you would add the onclick directly to it. What you would need to do is set the onclick to a function that will check the value and redirect based on it.

     

    e.g. First remove the change event from the select menu.

    <input type="button" name="btnAddToCart" value="Add To Cart >" onClick="setSize();" class="addToCartButton">
    
    function setSize()
    {
        var sizeVal = document.getElementById('pd_Size').options[pd_Size.selectedIndex].value;
        var hrefVal = '<?php echo $cart_url; ?>';
    
        if (sizeVal != '')
        {
            hrefVal = hrefVal + '&s=' + sizeVal;
        }
    
        location.href = hrefVal;
    }
    
  2. Let's say you have this html code <a href="#" class="contactlink" id="my_link_id_1">, you can use jquery to extract the id as the following

    $('.contactlink').click(function(){
       var id = this.id;
       id = id.split('_');
       id = id[id.length - 1];
       alert(id); // You can use $("#contact_id_"+id).slideToggle('fast'); here
    });
    

    

    

    

    

  3. Since your elements do not share a parent and they are not directly related, you would need to add either an id or a reference to link both of the elements (e.g. give the link an id "contactlink_id_1" and the div "contact_id_1").

     

    Otherwise, you would have to loop through the entire document and check if the contact element is after the element that fired the event (which is not optimal)..

  4. If you want your script to work like a native app without any loading, you would need to load the data into a javascript variable (e.g. array of arrays) and let javascript create the table with the page data on demand. You can store thousands of rows as data in an array without any performance lag put do not try to create the table for all of them as the same time. Just create the rows for the current page.

     

    You can also search about sorting etc in javascript.

  5. Without seeing the actual text, it's hard to debug. But it seems you are losing 10 characters when you slice your strings (slice to 90 and start from 100). A much easier solution would be to use CSS text-overflow.

  6. Since you are querying the elements using class name, you can give all the similar elements similar class and use this in the function. this will be the element that fired the event. You would need to add the events once.

     

    If you want to modify other related elements, you can get the parent node of this and use it as the context for your selection, e.g. $('.edit', this.parentNode).show();

    Just make sure each row has one parent element, e.g. <div id="parent_row_123"><div ,,,></div><div ...</div></div><!-- closing parent -->

  7. When you include parenthesis you are telling the browser to execute the function and assign the return value to the variable. And when you omit the parenthesis, you are telling the browser to assign the function itself to a variable. For example

    function returnA(){
        return 'A';
    }
    
    var my_A = returnA(); // my_A will be a string 'A';
    
    var my_A_func = returnA; // my_A_func will be a function that returns 'A'
    
    // using the new variables
    alert(my_A); // alerts 'A';
    alert(my_A_func) // alerts the function code
    alert( my_A_func() ) // alerts 'A'
    
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.