Click here to Skip to main content
15,886,835 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
I'm asp.net Developer and making a page .
I am use a Fancy sliding form in one page . I'm not very good in Jquery and Css code.
Fancy Sliding Form with jQuery[^]

in demo of this tutorials there are only 5 tabs,I want add 10 more tabs.Please any body give me solution.

My Jquery code is below .
JavaScript
$(function() {	
	var fieldsetCount = $('#formElem').children().length;
	
	var current 	= 1;
     
	var stepsWidth	= 0;
    var widths 		= new Array();
	$('#steps .step').each(function(i){
        var $step 		= $(this);
		widths[i]  		= stepsWidth;
        stepsWidth	 	+= $step.width();		
		$('#step').css('height','auto');
		
    });
	$('#step').width(stepsWidth);
	
	$('#pd').click(function(){
			$('#step').css('height','auto');
	});
	
	
	/* All Input field  */
	$('input, textarea').blur(function(){	   
	    var name = $(this).attr('ID') + "_li"; 
	        name = $("#" + name.substring(26)); 	        
	    if($(this).val() == ""){
	        name.css('list-style', 'url(../images/cross.png) inside');	                
    	}else{
			name.css('list-style', 'url(../images/tick.png) inside');
	    }
	});
	
	
	
	$('.selectBox ul li').click(function(){
	    alert("abc");
//	    var name = $(this).attr('ID') + "_li"; 
//	        name = $("#" + name.substring(26));
//	    if($(this).val() == ""){
//	        name.css('list-style','url(../images/cross.png) inside');	                
//    	}else{
//			name.css('list-style','url(../images/tick.png) inside');
//	    }
	});
    


	$('#formElem').children(':first').find('.city').focus();
	
	$('#navigation').show();
	
    $('#navigation a').bind('click',function(e){
		var $this	= $(this);
		var prev	= current;
		$this.closest('ul').find('li').removeClass('selected');
        $this.parent().addClass('selected');
						
		current = $this.parent().index() + 1;
		
        $('#steps').stop().animate({
            marginLeft: '-' + widths[current-1]* 1.027 + 'px'
        },500,function(){
					
			if(current == fieldsetCount)
				validateSteps();

			else
				validateStep(prev);
			$('#formElem').children(':nth-child('+ parseInt(current) +')').find(':input:first').focus();	
		});
        e.preventDefault();
    });
    
    $('.next').bind('click',function(e){
        var $this	= $(this);
		var prev	= current;
		
		$('#navigation ul li.selected').next().addClass('selected');
		$('#navigation ul li.selected').prev().removeClass('selected');
        
        //$this.parent().addClass('selected');
		current = $('#navigation ul li.selected').index() + 1;				
		
		
        $('#steps').stop().animate({   marginLeft: '-' + widths[current-1]* 1.027 + 'px'  }, 500, function(){
					
			if(current == fieldsetCount)
				validateSteps();

			else
				validateStep(prev);
			$('#formElem').children(':nth-child('+ parseInt(current) +')').find(':input:first').focus();	
		});
        e.preventDefault();
    });
    
    $('.prev').bind('click',function(e){
        var $this	= $(this);
		var prev	= current;
		
		$('#navigation ul li.selected').prev().addClass('selected');
		$('#navigation ul li.selected').next().removeClass('selected');
        
        //$this.parent().addClass('selected');
		current = $('#navigation ul li.selected').index() - 1;				
		
		
        $('#steps').stop().animate({   marginLeft: '-' + widths[current+1]* 1.027 + '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:not(button)').each(function(){
			var $this 		= $(this);
			var valueLength = jQuery.trim($this.val()).length;
			
			if(valueLength == ''){
				hasError = true;
				$this.css('background-color','#FFEDEF');
				
			}
			else
				$this.css('background-color','#FFFFFF');
				//$this.css('list-style','url(images/tick.png) inside');
				
		});
		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;
		}	
	});
});
Posted
Updated 3-Oct-13 2:33am
v5

1 solution

Problem

Posting only a code block and expecting answers from our side is a very bad idea.

Requirements

Please explain the requirement and scenario. We should know what exactly you are trying to achieve.

Issue

Next thing is - describe what you have tried to achieve the task.
If you are facing issues in the current code, then explain where exactly it is happening.

Suggestion

Use FireBug Console window (in FireFox) or other Developer tools of Browsers, to check all the client-side issues present in your code and try to resolve all of them.
 
Share this answer
 
v2
Comments
[no name] 3-Oct-13 8:10am    
I'm sorry if i could not explain well my question,Actually i'm not very good in Jquery Code and Css, I'm C# programer.
Well i try to explain what i want to do ,
Here is link of Jquery Slidng form ,
http://tympanus.net/Tutorials/FancySlidingForm/[^]
I'm using this tutorial to make sliding form in my asp.net page .
as you can see there are only 5 tabs in this plugin which is sliding by click.

So now i want put 10 more extra tabs and slid those form too.
My question is: Is i need to change some thing in Jquery code OR CSS for Add extra tabs????? give me trick please.
Okay, let me check. You want to add more tabs, right?
[no name] 3-Oct-13 8:17am    
Yes Right i want add more tabs :)
[no name] 3-Oct-13 8:23am    
i want add more tabs with form containing different fields(texbox,gridview etc ).
Okay I found the trick. You just need to add one new fieldset and navigation li.

I have added one like that and uploaded at - Fancy Sliding Form with 6 Tabs[^]

You can download and check how it is working.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900