2012-04-08 33 views
0

我的php頁面底部有幾個級聯下拉菜單。每次用戶從下拉菜單中選擇一個選項時,都會調用以下函數將該選項的值添加到我的url變量中。目前,頁面每次刷新到頂部都是一個巨大的問題。通常我會用onCLick =「window.location ='page.htm#bottom';」刷新到頁面的底部,但當添加#bottom時,下面的函數停止工作。有人可以幫助我調整這個功能,或者給我其他的想法,當功能完成時,它會刷新到頁面的底部。無法使用包含url變量的javascript函數刷新頁面底部

function reload5(form){ 
if(document.getElementById('fda1').checked) { 
var fda = '1'; 
}else if(document.getElementById('fda0').checked) { 
    var fda = '0'; 
} 

var val=form.category.options[form.category.options.selectedIndex].value; 
var val2=form.subcat.options[form.subcat.options.selectedIndex].value; 
var val3=form.subcat1.options[form.subcat1.options.selectedIndex].value; 
var val4=form.subcat2.options[form.subcat2.options.selectedIndex].value; 
var comp1=form.mname.options[form.mname.options.selectedIndex].text; 
var itemnum=document.getElementById('item').value; 
var desc=document.getElementById('desc').value; 
var quan=document.getElementById('quan').value; 
var list=document.getElementById('list').value; 
var uom=form.uom.options[form.uom.options.selectedIndex].text; 
self.location='add_products.php#bottom?fda=' + fda + '&desc=' + desc + '&quan=' + quan + '&list=' + list + '&uom=' + uom + '&item=' + itemnum + '&cat=' + val + '&cat2=' + val2 + '&cat3=' + val3 + '&cat4=' + val4 + '&comp=' + comp1 ; 
} 

所以這不起作用:self.location='add_products.php#bottom?fda=' + fda

但這:self.location='add_products.php?fda=' + fda

任何想法,把#bottom網頁?

回答

1

問題是散列必須出現在查詢字符串的末尾。文章見this。試試這個...(我也清理了代碼)

function reload5(form){ 
    var val=form.category.options[form.category.options.selectedIndex].value, 
     val2=form.subcat.options[form.subcat.options.selectedIndex].value, 
     val3=form.subcat1.options[form.subcat1.options.selectedIndex].value, 
     val4=form.subcat2.options[form.subcat2.options.selectedIndex].value, 
     comp1=form.mname.options[form.mname.options.selectedIndex].text, 
     itemnum=document.getElementById('item').value, 
     desc=document.getElementById('desc').value, 
     quan=document.getElementById('quan').value, 
     list=document.getElementById('list').value, 
     uom=form.uom.options[form.uom.options.selectedIndex].text, 
     fda; 

    if(document.getElementById('fda1').checked) { 
     fda = 1; 
    } else if(document.getElementById('fda0').checked) { 
     fda = 0; 
    } else { 
     fda = -1; 
    } 

    window.self.location.href = 'add_products.php?fda=' + fda + '&desc=' + desc + '&quan=' + quan + '&list=' + list + '&uom=' + uom + '&item=' + itemnum + '&cat=' + val + '&cat2=' + val2 + '&cat3=' + val3 + '&cat4=' + val4 + '&comp=' + comp1 + "#bottom"; 
} 

我不明白的是你爲什麼不用Ajax做一些不會導致頁面刷新的東西。

+0

您的救星。謝謝一堆。特別是爲了清理代碼。我還沒有走過Ajax的原因是我是一個新手,但去年我寫這個頁面時真的是一個新手。我現在可能已經脫身了,但沒有得到它。再次感謝! – 2012-04-08 17:00:40