滑块形式问题

时间:2010-11-23 16:05:44

标签: javascript jquery

当用户点击它滑到下一步的包时,我该如何做到这一点?而不必单击底部的按钮。还有,有办法知道他们选择了哪个包。

这是目前的链接。

http://www.prototypesyndicate.com/_forms/marketing_packages.html

以下是html代码

<div id="wrapper">
                <div id="steps">
                    <form id="formElem" name="formElem" action="../send_marketing.php" method="post">
                        <fieldset class="step">
                            <legend>Select a Marketing Package</legend>

                            <!--**************************** PACKAGES ****************************-->

<div class="grid" id="griddler_ii">
 <div class="sections col3">
  <div>
   <article class="first">
    <header>
     <hgroup class="plan"><h1>Student</h1></hgroup>
     <hgroup class="price"><h2>$10<em>Monthly</em></h2></hgroup>
    </header>
    <section>
     <ul>
      <li>$20</li>
       <li>4.0%</li>
       <li>400</li>
       <li>100MB</li>
       <li>500GB</li>
      <li>&nbsp;</li>
     </ul>
    </section>
    <footer>
     <a class="button" href="#"><span>Choose Plan</span></a></li>
    </footer>
   </article>
   <article class="selected">
    <header>
     <hgroup class="plan"><h1>Professional</h1></hgroup>
     <hgroup class="price"><h2>$20<em>Monthly</em></h2><h4 class="label">Best value</h4></hgroup>
    </header>
    <section>
     <ul>
      <li>Waived</li>
       <li>3.0%</li>
      <li class="tooltip-holder">1000
        <div class="tooltip">
        <div>
         <h3>Available Space</h3>
         <p>Duis volutpat nisl ac ante pulvinar non lobortis urna adipiscing. In hac habitasse platea dictumst. </p>
        </div>
       </div></li>
      <li class="tooltip-holder">400MB
        <div class="tooltip">
        <div>
         <h3>Available Space</h3>
         <p>Duis volutpat nisl ac ante pulvinar non lobortis urna adipiscing. In hac habitasse platea dictumst. </p>
        </div>
       </div></li>
      <li class="tooltip-holder">1000
        <div class="tooltip">
        <div>
         <h3>Available Space</h3>
         <p>Duis volutpat nisl ac ante pulvinar non lobortis urna adipiscing. In hac habitasse platea dictumst. </p>
        </div>
       </div>
      </li>
      <li><span class="check">Yes</span></li>
     </ul>
    </section>
    <footer>
     <a class="button" href="#"><span>Choose Plan</span></a>
    </footer>
   </article>
   <article class="last">
    <header>
     <hgroup class="plan"><h1>Premium</h1></hgroup>
     <hgroup class="price"><h2>$40<em>Monthly</em></h2></hgroup>
    </header>
    <section>
     <ul>
      <li>Waived</li>
       <li>1.0%</li>
       <li>Unlimited</li>
       <li>10GB</li>
       <li>Unlimited</li>
      <li><span class="check">Yes</span></li>
     </ul>
    </section>
    <footer>
     <a class="button" href="#"><span>Choose Plan</span></a>
    </footer>
   </article>
  </div>
 </div>
</div>
<!--[if IE 8]>
 <script type="text/javascript">
  $("#griddler_ii section ul li:nth-child(even)").addClass("even");
 </script>
<![endif]-->

<!--**************************** PACKAGES: END ****************************-->

                        </fieldset>
                        <fieldset class="step">
                            <legend class="tight">Provide Your Contact Information</legend>

       <p class="column2">
                                <label for="updates">Tell Us About Yourself?<br>(Your industry, about your customers, where you are based)</label>
                                <textarea name="description" rows="7" cols="20"></textarea>
                            </p>
                            <p>
                                <label for="name">Name&#42;:</label>
                                <input id="name" name="name" type="text" AUTOCOMPLETE=OFF class="required" />
                            </p>
                            <p>
                                <label for="company">Company:</label>
                                <input id="company" name="company" type="text" AUTOCOMPLETE=OFF />
                            </p>
                            <p>
                                <label for="website">Email&#42;:</label>
                                <input id="website" name="email" placeholder="e.g. tom@prototypesyndicate.com" type="text" AUTOCOMPLETE=OFF class="required" />
                            </p>
                            <p>
                                <label for="website">Website:</label>
                                <input id="website" name="website" type="text" AUTOCOMPLETE=ON />
                            </p>
                            <p>
                                <label for="phone">Phone&#42;:</label>
                                <input id="phone" name="phone" placeholder="e.g. +351215555555" type="tel" AUTOCOMPLETE=OFF class="required" />
                            </p>


                        </fieldset>

      <fieldset class="step">
       <br/><br/><br/><br/>
                             <p class="review">
         If all required fields in the form are correctly filled a green checkmark will appear. A red checkmark indicates that some required field is missing or filled out with invalid data.
        </p>
                             <p class="submit">
                                 <button id="registerButton" type="submit">Let&rsquo;s Begin</button>
                             </p>

                        </fieldset>

                    </form>
                </div>
                <div id="navigation" style="display:none;">
                    <ul>
                        <li>
                            <a href="#">Select a Packages</a>
                        </li>
                        <li>
                            <a href="#">Provide your Contact</a>
                        </li>
                        <li>
                            <a href="#">Let's Begin</a>
                        </li>
                    </ul>
                </div>
            </div>

JAVASCRIPT BELOW

$(function() {
    /*
    number of fieldsets
    */
    var fieldsetCount = $('#formElem').children().length;

    /*
    current position of fieldset / navigation link
    */
    var current     = 1;

    /*
    sum and save the widths of each one of the fieldsets
    set the final sum as the total width of the steps element
    */
    var stepsWidth  = 0;
    var widths      = new Array();
    $('#steps .step').each(function(i){
        var $step       = $(this);
        widths[i]       = stepsWidth;
        stepsWidth      += $step.width();
    });
    $('#steps').width(stepsWidth);

    /*
    to avoid problems in IE, focus the first input of the form
    */
    $('#formElem').children(':first').find(':input:first').focus(); 

    /*
    show the navigation bar
    */
    $('#navigation').show();

    /*
    when clicking on a navigation link 
    the form slides to the corresponding fieldset
    */
    $('#navigation a').bind('click',function(e){
        var $this   = $(this);
        var prev    = current;
        $this.closest('ul').find('li').removeClass('selected');
        $this.parent().addClass('selected');
        /*
        we store the position of the link
        in the current variable 
        */
        current = $this.parent().index() + 1;
        /*
        animate / slide to the next or to the corresponding
        fieldset. The order of the links in the navigation
        is the order of the fieldsets.
        Also, after sliding, we trigger the focus on the first 
        input element of the new fieldset
        If we clicked on the last link (confirmation), then we validate
        all the fieldsets, otherwise we validate the previous one
        before the form slided
        */
        $('#steps').stop().animate({
            marginLeft: '-' + widths[current-1] + 'px'
        },500,function(){
            if(current == fieldsetCount)
                validateSteps();
            else
                validateStep(prev);
            $('#formElem').children(':nth-child('+ parseInt(current) +')').find(':input:first').focus();    
        });
        e.preventDefault();
    });

    /*
    clicking on the tab (on the last input of each fieldset), makes the form
    slide to the next step
    */
    $('#formElem > fieldset').each(function(){
        var $fieldset = $(this);
        $fieldset.children(':last').find(':input').keydown(function(e){
            if (e.which == 9){
                $('#navigation li:nth-child(' + (parseInt(current)+1) + ') a').click();
                /* force the blur for validation */
                $(this).blur();
                e.preventDefault();
            }
        });
    });

    /*
    validates errors on all the fieldsets
    records if the Form has errors in $('#formElem').data()
    */
    function validateSteps(){
        var FormErrors = false;
        for(var i = 1; i < fieldsetCount; ++i){
            var error = validateStep(i);
            if(error == -1)
                FormErrors = true;
        }
        $('#formElem').data('errors',FormErrors);   
    }

    /*
    validates one fieldset
    and returns -1 if errors found, or 1 if not
    */
    function validateStep(step){
        if(step == fieldsetCount) return;

        var error = 1;
        var hasError = false;
        $('#formElem').children(':nth-child('+ parseInt(step) +')').find(':input.required:not(button)').each(function(){
            var $this       = $(this);
            var valueLength = jQuery.trim($this.val()).length;

            if(valueLength == ''){
                hasError = true;
                $this.css('background-color','#333333');
            }
            else
                $this.css('background-color','#000000');    
        });
        var $link = $('#navigation li:nth-child(' + parseInt(step) + ') a');
        $link.parent().find('.error,.checked').remove();

        var valclass = 'checked';
        if(hasError){
            error = -1;
            valclass = 'error';
        }
        $('<span class="'+valclass+'"></span>').insertAfter($link);

        return error;
    }

    /*
    if there are errors don't allow the user to submit
    */
    $('#registerButton').bind('click',function(){
        if($('#formElem').data('errors')){
            alert('Please correct the errors in the Form');
            return false;
        }   
    });
});

1 个答案:

答案 0 :(得分:0)

您需要查找为底部标签执行幻灯片的代码部分,并将相同的代码添加到onclick以进行包选择。您没有提供任何现有的JavaScript,因此很难知道代码的位置。