jQuery(function() { jQuery("select[name='type']").change(function() { jQuery('form.wizard').hide(0); rel = jQuery(this).attr('value'); jQuery("form[name='"+rel+"']").show('slow'); window.location.hash = 'category='+rel; }); jQuery('.submit').click(function() { jQuery(this).parents('form').submit(); return false; }); jQuery('form.wizard').submit(function() { var $form = jQuery(this); var type = this.name; window.location.hash = 'category='+type; rawData = jQuery(this).serializeArray(); jQuery.each(rawData, function(x, y) { window.location.hash += '&'+this.name+'='+this.value; }); data = {}; jQuery.each(rawData, function(x, y) { data[y.name] = y.value; }); jQuery.post('/ajax/productWizard.php', data, function(result) { jQuery('.') jQuery('.productList')[0].innerHTML = result; }); return false; }); if(window.location.hash != '') { buildFromHash(); } }); function buildFromHash() { hash = window.location.hash.replace('#', ''); if(hash != '') { pairs = hash.split('&'); jQuery("form.wizard").hide(0); jQuery.each(pairs, function(x, y) { pair = this.split('='); if(pair[0] == 'category') { form = jQuery("form[name='"+pair[1]+"']").show('slow'); cat = pair[1]; } else { elem = document.forms[cat][pair[0]]; if(/input/i.test(elem.nodeName) && elem.type == 'text') { elem.value = pair[1]; } else if(/select/i.test(elem.nodeName)) { jQuery.each(elem.options, function(x, y) { if(this.value == pair[1]) { this.selected = true; } }); } } }); form.submit(); } }