Javascript combine?

Discussion in 'JavaScript' started by sXe, May 28, 2012.

  1. #1
    Hey guys I'm having a bit of trouble running two scripts on the same webpage, one is for the top slider and the other is for a contact form, I been looking around trying to find how to combine them but I cant seem to find anything.

    Here is my code I need to combine:

    
    <script type="text/javascript" src="js/jquery-1.3.2.min.js"></script>
    <script type="text/javascript" src="js/jquery.cycle.all.min.js"></script>
    <script type="text/javascript">
    $(document).ready(function(){
        $('#slideshow').cycle({
            fx:     'fade',
            speed:  'slow',
            timeout: 2600,
            pager:  '#slider_nav',
            pagerAnchorBuilder: function(idx, slide) {
                // return sel string for existing anchor
                return '#slider_nav li:eq(' + (idx) + ') a';
            }
        });
    });
    </script>
    
    Code (markup):
    with

    
    <script type="text/javascript" src="js/jquery.cycle.all.min.js"></script>
    <script type="text/javascript" src="js/jquery-1.3.2.min.js"></script>
    
    <script type="text/javascript">
    // <![CDATA[
    jQuery(document).ready(function(){
        $('#contactform').submit(function(){                  
            var action = $(this).attr('action');
            $.post(action, { 
                name: $('#name').val(),
                email: $('#email').val(),
                subject: $('#subject').val(),
                message: $('#message').val()
            },
            
                function(data){
                    $('#contactform #submit').attr('disabled','');
                    $('.response').remove();
                    $('#contactform').before('<p class="response">'+data+'</p>');
                    $('.response').slideDown();
                    if(data=='Message sent!') $('#contactform').slideUp();
                }
            ); 
            return false;
        });
    });
    // ]]>
    </script>
    
    Code (markup):

    Appreciated if someone could help me out or point me in the right direction thanks in advance.
     
    sXe, May 28, 2012 IP
  2. HostPlanz

    HostPlanz Well-Known Member

    Messages:
    449
    Likes Received:
    34
    Best Answers:
    4
    Trophy Points:
    130
    #2
    How do you mean combine them? You mean like placing the in the same script tags, one function after the other?
     
    HostPlanz, May 28, 2012 IP
  3. dthoai

    dthoai Member

    Messages:
    106
    Likes Received:
    2
    Best Answers:
    1
    Trophy Points:
    38
    #3
    
    <script type="text/javascript" src="js/jquery-1.3.2.min.js"></script>
    <script type="text/javascript" src="js/jquery.cycle.all.min.js"></script>
    <script type="text/javascript">
    $(document).ready(function(){
        $('#slideshow').cycle({
            fx:     'fade',
            speed:  'slow',
            timeout: 2600,
            pager:  '#slider_nav',
            pagerAnchorBuilder: function(idx, slide) {
                // return sel string for existing anchor
                return '#slider_nav li:eq(' + (idx) + ') a';
            }
        });
        $('#contactform').submit(function(){                  
            var action = $(this).attr('action');
            $.post(action, { 
                name: $('#name').val(),
                email: $('#email').val(),
                subject: $('#subject').val(),
                message: $('#message').val()
            },
            
                function(data){
                    $('#contactform #submit').attr('disabled','');
                    $('.response').remove();
                    $('#contactform').before('<p class="response">'+data+'</p>');
                    $('.response').slideDown();
                    if(data=='Message sent!') $('#contactform').slideUp();
                }
            ); 
            return false;
        });	
    });
    </script>
    
    Code (markup):
     
    dthoai, May 28, 2012 IP
  4. suwandichen13

    suwandichen13 Well-Known Member

    Messages:
    618
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    140
    #4
    so how combine that all to be 1 script at head section??thanks
     
    suwandichen13, Jul 3, 2012 IP